celseeth / aima-python

Automatically exported from code.google.com/p/aima-python
0 stars 0 forks source link

Error in utility function for Tic Tac Toe makes 'X' always win #22

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Run the following
from games import *

ttt = TicTacToe(3,3,3)
play_game(ttt,alphabeta_player,alphabeta_player)

2. Note that X always win, and that O seems to help X to win

What is the expected output? What do you see instead?
Expected is that there will always be a draw.

What version of the product are you using? On what operating system?
Ubuntu 10.10

Here is a patch to solve the problem.
Check which player is making the move and negate the utility when the player is 
O.

class TicTacToe(Game):
     ...
    def utility(self, state, player):
        "Return the value to X; 1 for win, -1 for loss, 0 otherwise."
        if player=="O":
            return -state.utility
        else:
            return state.utility

Original issue reported on code.google.com by daniel.u...@gmail.com on 28 Feb 2011 at 6:55

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r54.

Original comment by wit...@gmail.com on 1 Sep 2011 at 10:18