GameDev.net Posting Guidelines (please read before posting)
Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 04 November 2010 - 10:44 PM
Posted 05 November 2010 - 01:05 AM
Quote:
Original post by mandar9589
In coding of negamax, using the normal pseudo code,what is the initial call to negamax function from the typical 'get_move' function?
is it
eval=-negamax(...);
or
eval=negamax(...);
eval=-negamax(...);
Quote:
My evaluation function returns -1000 for win.
Posted 05 November 2010 - 01:25 AM
Posted 05 November 2010 - 02:35 AM
public static int evaluate(char[][] posn, boolean white) {
int eval = 0;
'1'=empty
//Winning.
for (row = 0; row < rows; row++) {
for (column = 0; column < cols-3; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row][column + 1]
&& posn[row][column] == posn[row][column + 2]
&& posn[row][column] == posn[row][column + 3]) {
eval = fscore;
return eval;
}
}
}
// check for a vertical win
for (row = 0; row < rows-3; row++) {
for (column = 0; column < cols; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row + 1][column]
&& posn[row][column] == posn[row + 2][column]
&& posn[row][column] == posn[row + 3][column]) {
eval = fscore;
return eval;
}
}
}
// check for a diagonal win (positive slope)
for (row = 0; row < rows-3; row++) {
for (column = 0; column < cols-3; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row + 1][column + 1]
&& posn[row][column] == posn[row + 2][column + 2]
&& posn[row][column] == posn[row + 3][column + 3]) {
eval = fscore;
return eval;
}
}
}
// check for a diagonal win (negative slope)
for (row = 3; row < rows; row++) {
for (column = 0; column < cols-3; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row - 1][column + 1]
&& posn[row][column] == posn[row - 2][column + 2]
&& posn[row][column] == posn[row - 3][column + 3]) {
eval = fscore;
return eval;
}
}
}
//3in a row
for (row = 0; row < rows; row++) {
for (column = 0; column < cols-2; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row][column + 1]
&& posn[row][column] == posn[row][column + 2]) {
eval=eval+ _3inrow;
}
}
}
// check for 3-a vertical win
for (row = 0; row < rows-2; row++) {
for (column = 0; column < cols; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row + 1][column]
&& posn[row][column] == posn[row + 2][column]) {
eval=eval+ _3inrow;
}
}
}
// check for 3-a diagonal win (positive slope)
for (row = 0; row < rows-2; row++) {
for (column = 0; column < cols-2; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row + 1][column + 1]
&& posn[row][column] == posn[row + 2][column + 2]){
eval=eval+ _3inrow;
}
}
}
// check for 3- a diagonal win (negative slope)
for (row = 2; row < rows; row++) {
for (column = 0; column < cols-2; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row - 1][column + 1]
&& posn[row][column] == posn[row - 2][column + 2]) {
eval=eval+ _3inrow;
}
}
}
return eval;
}
public static int evaluate(char[][] posn, boolean white) {
char color = white ? 'x' : 'o';
int eval = 0;
//Winning.
for (row = 0; row < rows; row++) {
for (column = 0; column < cols - 3; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row][column + 1]
&& posn[row][column] == posn[row][column + 2]
&& posn[row][column] == posn[row][column + 3]) {
eval = fscore;
if (color == 'x') {
return eval;
}
if (color == 'o') {
return -eval;
}
}
}
}
// check for a vertical win
for (row = 0; row < rows - 3; row++) {
for (column = 0; column < cols; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row + 1][column]
&& posn[row][column] == posn[row + 2][column]
&& posn[row][column] == posn[row + 3][column]) {
eval = fscore;
if (color == 'x') {
return eval;
}
if (color == 'o') {
return -eval;
}
}
}
}
// check for a diagonal win (positive slope)
for (row = 0; row < rows - 3; row++) {
for (column = 0; column < cols - 3; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row + 1][column + 1]
&& posn[row][column] == posn[row + 2][column + 2]
&& posn[row][column] == posn[row + 3][column + 3]) {
eval = fscore;
if (color == 'x') {
return eval;
}
if (color == 'o') {
return -eval;
}
}
}
}
// check for a diagonal win (negative slope)
for (row = 3; row < rows; row++) {
for (column = 0; column < cols - 3; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row - 1][column + 1]
&& posn[row][column] == posn[row - 2][column + 2]
&& posn[row][column] == posn[row - 3][column + 3]) {
eval = fscore;
if (color == 'x') {
return eval;
}
if (color == 'o') {
return -eval;
}
}
}
}
//3in a row
for (row = 0; row < rows; row++) {
for (column = 0; column < cols - 2; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row][column + 1]
&& posn[row][column] == posn[row][column + 2]) {
eval = eval + _3inrow;
}
}
}
// check for 3-a vertical win
for (row = 0; row < rows - 2; row++) {
for (column = 0; column < cols; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row + 1][column]
&& posn[row][column] == posn[row + 2][column]) {
eval = eval + _3inrow;
}
}
}
// check for 3-a diagonal win (positive slope)
for (row = 0; row < rows - 2; row++) {
for (column = 0; column < cols - 2; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row + 1][column + 1]
&& posn[row][column] == posn[row + 2][column + 2]) {
eval = eval + _3inrow;
}
}
}
// check for 3- a diagonal win (negative slope)
for (row = 2; row < rows; row++) {
for (column = 0; column < cols - 2; column++) {
if (posn[row][column] != '1'
&& posn[row][column] == posn[row - 1][column + 1]
&& posn[row][column] == posn[row - 2][column + 2]) {
eval = eval + _3inrow;
}
}
}
//....
if (color == 'o') {
return -eval;
}
return eval;
}
Posted 05 November 2010 - 03:41 AM
Quote:
Original post by alvaro
Quote:
Original post by BitSet
Well I cannot agree.
What is it you don't agree with?
for (i = 1; i <= max_depth; ++i) {
follow_pv = TRUE;
x = search(-10000, 10000, i);
if (output == 1)
printf("%3d %9d %5d ", i, nodes, x);
else if (output == 2)
printf("%d %d %d %d",
i, x, (get_ms() - start_time) / 10, nodes);
if (output) {
for (j = 0; j < pv_length[0]; ++j)
printf(" %s", move_str(pv[0][j].b));
printf("\n");
fflush(stdout);
}
if (x > 9000 || x < -9000)
break;
}
/* loop through the moves */
for (i = first_move[ply]; i < first_move[ply + 1]; ++i) {
sort(i);
if (!makemove(gen_dat[i].m.b))
continue;
f = TRUE;
x = -search(-beta, -alpha, depth - 1);
takeback();
if (x > alpha) {
/* this move caused a cutoff, so increase the history
value so it gets ordered high next time we can
search it */
history[(int)gen_dat[i].m.b.from][(int)gen_dat[i].m.b.to] += depth;
if (x >= beta)
return beta;
alpha = x;
/* update the PV */
pv[ply][ply] = gen_dat[i].m;
for (j = ply + 1; j < pv_length[ply + 1]; ++j)
pv[ply][j] = pv[ply + 1][j];
pv_length[ply] = pv_length[ply + 1];
}
}
Quote:
So does your suggestion and my code match?
Posted 05 November 2010 - 06:57 AM
Quote:
Original post by BitSet
I don't agree there is minus in the front of negamax root node call, for example in ID framework.
I'm talking about this (from TSCP 1.81):
*** Source Snippet Removed ***
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.