What's new About Download License Screenshots Manual Tutorial sf.net page Contact |
7. Make it less deterministicNow, our program is able to attack and defend itself as well. However, the moves are deterministic, which makes it less fun to play with. In this section, we'll make the program less deterministic.Let's open boora-0.6.wz with a text editor and save it as boora-0.7.wz. Modify function makemove() of AI class to accommodate the newly-added function exploringmove(). (Listing 7-1)
Instead of always choosing the move that has the biggest value, function exploringmove() randomly picks up a move among those that have top values. (Listing 7-2) The for-loop counts the number of moves which have top values. It compares the values of moves with the biggest, and chooses these whose the relative difference is less than delta. Variable delta takes values between 0 and 1 and determines the randomness of the program: the bigger the value, the less deterministic and the weaker the program.
Add delta as a data member and initialize it in initDelta(). (Listing 7-3) Function initDelta() guarantees that delta gets a valid value.
Accordingly, modify initAI()to invoke initDelta() and set random number seed.
Modify function newAI() in order to pass in a value to delta. (Listing 7-5)
Modify function tick5think(). (Listing 7-5) We choose 0.15 for delta, because we want randomness but don't want the program too weak.
Play against the program. We notice that its moves are less deterministic. Let it play against predecessor boora-0.6.wz, it roughly has the same chance to win, no matter whether it plays black or white stone. |