Created
December 7, 2015 03:00
-
-
Save armstrongnate/8ebf196e87f7a2ca4665 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ai::Agent::Action * Chan::Program(const ai::Agent::Percept * percept) | |
{ | |
ai::CCheckers::Action *action = new ai::CCheckers::Action; | |
ai::CCheckers::MoveData move; | |
std::string board_str = percept->GetAtom("BASIC_BOARD").GetValue(); | |
ai::CCheckers::BasicBoard board(board_str); | |
int player = atoi(percept->GetAtom("PLAYER_NUMBER").GetValue().c_str()); | |
const std::vector<ai::CCheckers::MoveData> & moves = board.DetermineLegalMoves(player); | |
int best_forwardness = -1; | |
unsigned int best_move = 0; | |
for (unsigned int i=0; i<moves.size(); i++) | |
{ | |
ai::CCheckers::BasicBoard b(board); | |
b.Move(player, move); | |
int forwardness = b.Forwardness(player); | |
std::cout << "forwardness: " << forwardness << ", i: " << i << std::endl; | |
bool chooseThisMove = false; | |
if (forwardness > best_forwardness) | |
{ | |
chooseThisMove = true; | |
} | |
if (chooseThisMove) | |
{ | |
best_forwardness = forwardness; | |
best_move = i; | |
} | |
} | |
if (moves.size() > 0) | |
{ | |
move = moves[best_move]; | |
} | |
action->SetMove(move); | |
action->SetCode(ai::CCheckers::Action::MOVE); | |
return action; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment