Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
GoogleCodeExporter opened this issue Aug 29, 2015 · 1 comment
Closed

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

This issue was closed by revision r54.

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

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant