Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualAticAtac

Posted 24 September 2012 - 03:40 AM

Yes, all pieces (except those in the base) move one step in the same direction. For left player e.g. the movement starts with the pieces from right-to-left, so one cann't land at own piece.
Thankls for the link i will look at.

Meanwhile, here my minimax-code:


[source lang="cpp"]//--------------------------------------------------------------------------------int cBoard::MiniMaxAB(tBoard& board, int depth, int alpha, int beta, int sumscore, bool left){ if (depth == _maxdepth) return sumscore; std::vector<tMove> movelist; GenerateMoves(&board, left, movelist); if (movelist.size() == 0) return sumscore; int this_alpha = -1000000; int this_beta = +1000000; // Max node if (left == _cpuleft) { for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &board, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int score = movelist[i].rating; int val = MiniMaxAB(board2, depth+1, Max(alpha, this_alpha), beta, sumscore+score, !left); this_alpha = Max(this_alpha, val); if (this_alpha >= beta) { break; } } return this_alpha; } else { for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &board, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int score = -movelist[i].rating; int val = MiniMaxAB(board2, depth+1, alpha, Min(beta, this_beta), sumscore+score, !left); this_beta = Min(this_beta, val); if (alpha >= this_beta) { break; } } return this_beta; } return 0;}//--------------------------------------------------------------------------------tMove cBoard::MiniMaxAB(bool left, int maxdepth){ _cpuleft = left; _maxdepth = maxdepth; tMove bestmove; bestmove.rating = -1000000; int currentscore; _bestmoves.clear(); std::vector<tMove> movelist; GenerateMoves(&m_fields, left, movelist); for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &m_fields, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int rating = movelist[i].rating; currentscore = MiniMaxAB(board2, 0, -1000000, +1000000, rating, !left); if (currentscore > bestmove.rating) { bestmove.rating = currentscore; bestmove.move = movelist[i].move; } tMove move; move.move = movelist[i].move; move.rating = currentscore; _bestmoves.push_back(move); } return bestmove;}[/source]

The starting function is MiniMaxAB(bool left, int maxdepth), where for "left"=true the cpu player is on the left side else right side.
The evaluation of a  move is done in the function ExecuteMove(...)

P.S: My Code in the code snippet doesn't seem to be shon correctly, parts are missing, is that a known bug?
E.g. i can only see
"GenerateMoves(&m_fields, left, movelist);
for (unsigned int i=0; i bestmove.rating)
{
bestmove.rating = currentscore;
bestmove.move = movelist[i].move;
}
..."

but it should be

"GenerateMoves(&m_fields, left, movelist);
for (unsigned int i=0; i<movelist.size(); ++i)
{
  tBoard board2;
  memcpy(&board2, &m_fields, sizeof(tBoard));
  ExecuteMove(&board2, left, movelist[i]);
  int rating = movelist[i].rating;
  currentscore = MiniMaxAB(board2, 0, -1000000, +1000000, rating, !left);
  if (currentscore > bestmove.rating)
  {
   bestmove.rating = currentscore;
   bestmove.move = movelist[i].move;  
  }
  tMove move;
  move.move = movelist[i].move;
  move.rating = currentscore;
  _bestmoves.push_back(move);
}
"

#4AticAtac

Posted 24 September 2012 - 03:39 AM

Yes, all pieces (except those in the base) move one step in the same direction. For left player e.g. the movement starts with the pieces from right-to-left, so one cann't land at own piece.
Thankls for the link i will look at.

Meanwhile, here my minimax-code:


[source lang="cpp"]//--------------------------------------------------------------------------------int cBoard::MiniMaxAB(tBoard& board, int depth, int alpha, int beta, int sumscore, bool left){ if (depth == _maxdepth) return sumscore; std::vector<tMove> movelist; GenerateMoves(&board, left, movelist); if (movelist.size() == 0) return sumscore; int this_alpha = -1000000; int this_beta = +1000000; // Max node if (left == _cpuleft) { for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &board, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int score = movelist[i].rating; int val = MiniMaxAB(board2, depth+1, Max(alpha, this_alpha), beta, sumscore+score, !left); this_alpha = Max(this_alpha, val); if (this_alpha >= beta) { break; } } return this_alpha; } else { for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &board, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int score = -movelist[i].rating; int val = MiniMaxAB(board2, depth+1, alpha, Min(beta, this_beta), sumscore+score, !left); this_beta = Min(this_beta, val); if (alpha >= this_beta) { break; } } return this_beta; } return 0;}//--------------------------------------------------------------------------------tMove cBoard::MiniMaxAB(bool left, int maxdepth){ _cpuleft = left; _maxdepth = maxdepth; tMove bestmove; bestmove.rating = -1000000; int currentscore; _bestmoves.clear(); std::vector<tMove> movelist; GenerateMoves(&m_fields, left, movelist); for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &m_fields, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int rating = movelist[i].rating; currentscore = MiniMaxAB(board2, 0, -1000000, +1000000, rating, !left); if (currentscore > bestmove.rating) { bestmove.rating = currentscore; bestmove.move = movelist[i].move; } tMove move; move.move = movelist[i].move; move.rating = currentscore; _bestmoves.push_back(move); } return bestmove;}[/source]

The starting function is MiniMaxAB(bool left, int maxdepth), where for "left"=true the cpu player is on the left side else right side.
The evaluation of a  move is done in the function ExecuteMove(...)

P.S: My Code in the code snippet doesn't seem to be shon correctly, parts are missing, is that a known bug?
E.g. i can only see
"GenerateMoves(&m_fields, left, movelist);
    for (unsigned int i=0; i bestmove.rating)
    {
    bestmove.rating = currentscore;
    bestmove.move = movelist[i].move;
    }
..."

but it should be

"GenerateMoves(&m_fields, left, movelist);
for (unsigned int i=0; i<movelist.size(); ++i)
{
  tBoard board2;
  memcpy(&board2, &m_fields, sizeof(tBoard));
  memset(&eval, 0, sizeof(tEvaluation));
  ExecuteMove(&board2, left, movelist[i], eval);
  int rating = movelist[i].rating;
  currentscore = MiniMaxAB(board2, 0, -1000000, +1000000, rating, !left);
  if (currentscore > bestmove.rating)
  {
   bestmove.rating = currentscore;
   bestmove.move = movelist[i].move;  
  }
  tMove move;
  move.move = movelist[i].move;
  move.rating = currentscore;
  _bestmoves.push_back(move);
}
"

#3AticAtac

Posted 24 September 2012 - 01:37 AM

Yes, all pieces (except those in the base) move one step in the same direction. For left player e.g. the movement starts with the pieces from right-to-left, so one cann't land at own piece.
Thankls for the link i will look at.

Meanwhile, here my minimax-code:


[source lang="cpp"]//--------------------------------------------------------------------------------int cBoard::MiniMaxAB(tBoard& board, int depth, int alpha, int beta, int sumscore, bool left){ if (depth == _maxdepth) return sumscore; std::vector<tMove> movelist; GenerateMoves(&board, left, movelist); if (movelist.size() == 0) return sumscore; int this_alpha = -1000000; int this_beta = +1000000; // Max node if (left == _cpuleft) { for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &board, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int score = movelist[i].rating; int val = MiniMaxAB(board2, depth+1, Max(alpha, this_alpha), beta, sumscore+score, !left); this_alpha = Max(this_alpha, val); if (this_alpha >= beta) { break; } } return this_alpha; } else { for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &board, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int score = -movelist[i].rating; int val = MiniMaxAB(board2, depth+1, alpha, Min(beta, this_beta), sumscore+score, !left); this_beta = Min(this_beta, val); if (alpha >= this_beta) { break; } } return this_beta; } return 0;}//--------------------------------------------------------------------------------tMove cBoard::MiniMaxAB(bool left, int maxdepth){ _cpuleft = left; _maxdepth = maxdepth; tMove bestmove; bestmove.rating = -1000000; int currentscore; _bestmoves.clear(); std::vector<tMove> movelist; GenerateMoves(&m_fields, left, movelist); for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &m_fields, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int rating = movelist[i].rating; currentscore = MiniMaxAB(board2, 0, -1000000, +1000000, rating, !left); if (currentscore > bestmove.rating) { bestmove.rating = currentscore; bestmove.move = movelist[i].move; } tMove move; move.move = movelist[i].move; move.rating = currentscore; _bestmoves.push_back(move); } return bestmove;}[/source]

The starting function is MiniMaxAB(bool left, int maxdepth), where for "left"=true the cpu player is on the left side else right side.
The evaluation of a  move is done in the function ExecuteMove(...)

#2AticAtac

Posted 24 September 2012 - 01:36 AM

Yes, all pieces (except those in the base) move one step in the same direction. For left player e.g. the movement starts with the pieces from right-to-left, so one cann't land at own piece.
Thankls for the link i will look at.

Meanwhile, here my minimax-code:


[source lang="cpp"]//--------------------------------------------------------------------------------int cBoard::MiniMaxAB(tBoard& board, int depth, int alpha, int beta, int sumscore, bool left){ if (depth == _maxdepth) return sumscore; std::vector<tMove> movelist; GenerateMoves(&board, left, movelist); if (movelist.size() == 0) return sumscore; int this_alpha = -1000000; int this_beta = +1000000; // Max node if (left == _cpuleft) { for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &board, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int score = movelist[i].rating; int val = MiniMaxAB(board2, depth+1, Max(alpha, this_alpha), beta, sumscore+score, !left); this_alpha = Max(this_alpha, val); if (this_alpha >= beta) { break; } } return this_alpha; } else { for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &board, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int score = -movelist[i].rating; int val = MiniMaxAB(board2, depth+1, alpha, Min(beta, this_beta), sumscore+score, !left); this_beta = Min(this_beta, val); if (alpha >= this_beta) { break; } } return this_beta; } return 0;}//--------------------------------------------------------------------------------tMove cBoard::MiniMaxAB(bool left, int maxdepth){ _cpuleft = left; _maxdepth = maxdepth; tMove bestmove; bestmove.rating = -1000000; int currentscore; _bestmoves.clear(); std::vector<tMove> movelist; GenerateMoves(&m_fields, left, movelist); for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &m_fields, sizeof(tBoard)); ExecuteMove(&board2, left, movelist[i]); int rating = movelist[i].rating; currentscore = MiniMaxAB(board2, 0, -1000000, +1000000, rating, !left); if (currentscore > bestmove.rating) { bestmove.rating = currentscore; bestmove.move = movelist[i].move; } tMove move; move.move = movelist[i].move; move.rating = currentscore; _bestmoves.push_back(move); } return bestmove;}[/source]

The starting function is MiniMaxAB(bool left, int maxdepth), where fpr "left"=true the cpu player is on the left side else right side.

#1AticAtac

Posted 24 September 2012 - 01:32 AM

Yes, all pieces (except those in the base) move one step in the same direction. For left player e.g. the movement starts with the pieces from right-to-left, so one cann't land at own piece.
Thankls for the link i will look at.

Meanwhile, here my minimax-code:

[source lang="cpp"]//--------------------------------------------------------------------------------tMove cBoard::MiniMaxAB(bool left, int maxdepth){ tEvaluation eval; _cpuleft = left; _maxdepth = maxdepth; tMove bestmove; bestmove.rating = -1000000; int currentscore; _bestmoves.clear(); std::vector<tMove> movelist; GenerateMoves(&m_fields, left, movelist); for (unsigned int i=0; i<movelist.size(); ++i) { tBoard board2; memcpy(&board2, &m_fields, sizeof(tBoard)); memset(&eval, 0, sizeof(tEvaluation)); ExecuteMove(&board2, left, movelist[i], eval); int rating = movelist[i].rating; currentscore = MiniMaxAB(board2, 0, -1000000, +1000000, rating, !left); if (currentscore > bestmove.rating) { bestmove.rating = currentscore; bestmove.move = movelist[i].move; } tMove move; move.move = movelist[i].move; move.rating = currentscore; _bestmoves.push_back(move); } return bestmove;}//--------------------------------------------------------------------------------int cBoard::MiniMaxAB(tBoard& board, int depth, int alpha, int beta, int sumscore, bool left){tEvaluation eval;if (depth == _maxdepth) return sumscore;std::vector<tMove> movelist;GenerateMoves(&board, left, movelist);if (movelist.size() == 0) return sumscore;int this_alpha = -1000000;int this_beta = +1000000;// Max nodeif (left == _cpuleft){  for (unsigned int i=0; i<movelist.size(); ++i)  {   tBoard board2;   memcpy(&board2, &board, sizeof(tBoard));     memset(&eval, 0, sizeof(tEvaluation));   ExecuteMove(&board2, left, movelist[i], eval);   int score = movelist[i].rating;   int val = MiniMaxAB(board2, depth+1, Max(alpha, this_alpha), beta, sumscore+score, !left);   this_alpha = Max(this_alpha, val);   if (this_alpha >= beta)   {    break;   }  }  return this_alpha;} else{  for (unsigned int i=0; i<movelist.size(); ++i)  {   tBoard board2;   memcpy(&board2, &board, sizeof(tBoard));   memset(&eval, 0, sizeof(tEvaluation));   ExecuteMove(&board2, left, movelist[i], eval);   int score = -movelist[i].rating;   int val = MiniMaxAB(board2, depth+1, alpha, Min(beta, this_beta), sumscore+score, !left);   this_beta = Min(this_beta, val);   if (alpha >= this_beta)   {    break;   }  }  return this_beta;}return 0;}[/source]

PARTNERS