15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

418<br />

Adversarial Search<br />

Figure 2-8:<br />

Clustered<br />

indexes<br />

physically<br />

rearrange<br />

data<br />

whereas<br />

unclustered<br />

indexes<br />

point to<br />

data.<br />

555-0147<br />

555-1462<br />

555-7001<br />

555-8163<br />

555-8772<br />

555-9604<br />

Unclustered index<br />

Adams<br />

Gullins<br />

Hall<br />

Perkins<br />

Smith<br />

Wiggins<br />

Clustered index<br />

Mary 555-7001<br />

Travis 555-0147<br />

Gail 555-8772<br />

Sam 555-8136<br />

John 555-1462<br />

Nancy 555-9604<br />

Problems with indexes<br />

A single clustered index makes sense because it rearranges data in a specific<br />

way. Multiple, unclustered indexes can help search data in different ways.<br />

Although indexes make searching faster, they make inserting and deleting<br />

slower because every time you add or delete data, you must update and<br />

organize the index at the same time.<br />

If you’ve created multiple indexes, adding or deleting data means having to<br />

update every multiple index. If you have a small amount of data, creating<br />

and using an index may be more trouble than it’s worth. Only when you have<br />

large amounts of data is an index (or multiple indexes) worth using.<br />

Adversarial Search<br />

One of the most popular uses <strong>for</strong> searching is an adversarial search. This<br />

type of search is often used to create artificial intelligence in video games.<br />

Essentially, the computer analyzes the current game situation, such as a tictac-toe<br />

game, and calculates its list of possible moves. For each possible<br />

move, the computer creates a tree where the root node represents one of the<br />

computer’s possible moves and each alternating level represents the human<br />

opponent’s possible counter-moves, as shown in Figure 2-9.<br />

Each possible move is given a specific value:<br />

✦ A high value signifies a good move.<br />

✦ A negative value signifies a bad move.<br />

Assuming the human opponent chooses one possible counter-move, the<br />

next level of the tree displays the computer’s possible responses and so on.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!