I have table and some functions like Generate_moves() etc. but for the minmax algorithm to work I need to set a score for tables to make the computer choose the best table.
public int Score()
{
if (Turn == "X")
{
if (gameWon("X")) return 100;
if (gameWon("O")) return -100;
if (gameDrawn()) return 0;
return n - canWin("X");
}
if (Turn == "O")
{
if (gameWon("O")) return 100;
if (gameWon("X")) return -100;
if (gameDrawn()) return 0;
return n - canWin("O");
}
return -1;
}
My canWin(string)
returns a number that tells me how many Xs or Os i have in a straight line or column but I doubt it is a great why to set the score for a table.
If I have the table:
X - X
0 X 0
- - 0
the score should be the same as
X - -
0 - X
0 0 X
and should be bigger than
X - X
0 - -
- 0 -
And I don't have any idea how to make the Score function tell me different scores. How can I implement the method Score to tell me this?
Edit:
if computer is first with X and me with O
X - - X - - X - - X - -
- - - -> 0 - - -> 0 X - -> 0 X -
- - - - - - - - - - - 0
now how can i make the computer choose that the next best option is
X - X
0 X -
- - 0