Skip to content

Commit

Permalink
bestscore
Browse files Browse the repository at this point in the history
  • Loading branch information
abarriel committed Apr 25, 2018
1 parent f4045b0 commit f1c0224
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
22 changes: 1 addition & 21 deletions ai
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,8 @@ n # Player 1 if n == AI
player1
y # Player 2 if n == AI
player2
y
n
2 # next player
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . 1 . . . . . . . .
. . . . . . . . 2 2 . . . . . . . . .
. . . . . . . 1 2 1 . . . . . . . . .
. . . . . 1 2 2 2 2 1 . . . . . . . .
. . . . . 1 2 1 1 2 1 1 . . . . . . .
. . . . . 1 1 1 2 1 2 . . . . . . . .
. . . . . . 2 1 2 2 2 2 1 . . . . . .
. . . . . . . 1 2 . . . 1 . . . . . .
. . . . . . . 2 . . . . . . . . . . .
. . . . . . 1 . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
Expand Down
6 changes: 5 additions & 1 deletion src/BotHenry.class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ unsigned short int BotHenry::play(std::map<unsigned short, char> grid, char valu
if (ret[3]) std::cout << "\tgetAttack(3): " << ret[3] << " (" << ((ret[3] & 0xFFFF) >> 8) <<","<< (ret[3] & 0xFF) <<")"<<std::endl;
auto end = std::chrono::high_resolution_clock::now();
std::cout << "\tchoose: " << ret[0] << std::endl;
std::cout << std::chrono::duration<double, std::milli>(end - startAlgo).count() << " ms thread: "<< std::chrono::duration<double, std::milli>(end - realStart).count() << " ms \n";
std::cout << std::chrono::duration<double, std::milli>(end - startAlgo).count() << " ms "<< std::fixed << std::setprecision(2) << std::chrono::duration<double, std::milli>(end - realStart).count() / 1000 << " s \n";
run = true;
score_done = false;
return ret[0];
Expand Down Expand Up @@ -297,6 +297,10 @@ char mode, bool noDouble, char currentPoint, char oponentPoint, char depth, unsi
pos = moves.front() & 0xFFFF;
BotHenry::undoPlay(grid, moves.front() & 0xFFFF);
moves.erase(moves.begin());
for(int mov: (moves)) {
if (depth == MAX_DEPTH)
std::cout << "\t\t( why le x et y inverser?" << ((int)((mov & 0xFFFF) >> 8)) << "," << ((int)((mov & 0xFFFF) & 0xFF)) << ") s:" << (int)(mov >> 16) << std::endl;
}
if (tmpScore >= alpha)
alpha = tmpScore;
if (tmpScore < beta)
Expand Down
14 changes: 12 additions & 2 deletions src/GameManager.class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,24 @@ GameManager::GameManager( bool asking ) :
this->noDoubleThrees = false;
std::cout << "Human player 1 (Y/n): ";
std::getline(std::cin, res);
if (res.at(0) == 'n')
if (res.at(0) == 'n' && !this->gameMode)
this->PlayerOne = new BotHenry();
else if(res.at(0) == 'n')
{
std::cout << "ai can only be play in standard mode" << std::endl;
throw std::exception();
}
else
this->PlayerOne = new Human();
std::cout << "Human player 2 (Y/n): ";
std::getline(std::cin, res);
if (res.at(0) == 'n')
if (res.at(0) == 'n' && !this->gameMode)
this->PlayerTwo = new BotHenry();
else if(res.at(0) == 'n')
{
std::cout << "ai can only be play in standard mode" << std::endl;
throw std::exception();
}
else
this->PlayerTwo = new Human();
}
Expand Down
14 changes: 9 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ int main( int argc, char const **argv )
bool quit(false);
GameManager *GameMan;
// GameManager::instance();
if (argc == 2 && strncmp("default", argv[1], 7) == 0)
GameMan = GameManager::instance(false);
else
GameMan = GameManager::instance(true);
try {
if (argc == 2 && strncmp("default", argv[1], 7) == 0)
GameMan = GameManager::instance(false);
else
GameMan = GameManager::instance(true);
} catch (std::exception &e) {
delete GameMan;
return 0;
}
SDLMan = new SDLManager();
GameMan->printGrid(SDLMan);
SDLMan->render();
Expand All @@ -33,7 +38,6 @@ int main( int argc, char const **argv )
}
}
} catch (std::exception &e) {
std::cout << e.what() << std::endl;
quit = true;
}
}
Expand Down

0 comments on commit f1c0224

Please sign in to comment.