Ejemplo n.º 1
0
int main(void)
{
	std::array<std::array<std::shared_ptr<Figure>, 8>, 8> board;
	AI playerOne(AI_EASY, true, board);
	AI playerTwo(AI_EASY, false, board);

	std::shared_ptr<Figure> figure = NULL;
	sf::Vector2i new_position;

	while(figure == NULL)
	{
		Move move =  playerOne.playerTurn(board, playerTwo.getFigureSet() );

		figure = move.getFigure();
		new_position = move.getNewPosition();

		// wait some time
		sf::sleep(sf::microseconds(100) );
	}

	std::cout << "Old position:\t" << figure->getPosition().x << "\t" << figure->getPosition().y
		<< std::endl << "New position:\t" << new_position.x << "\t" << new_position.y << std::endl << std::endl;

	system("Pause");
	return 0;
}
Ejemplo n.º 2
0
int main (int argc, char *argv[]) {
    othelloBoard board;

    int choice;
    cout << "Load a game or start a new one?\n";
    cout << "1 -> Load a saved board state\n";
    cout << "2 -> Start a new game\n";

    bool validSelection = false;

    do {
        cout << "Selection: ";

        string str;
        cin >> str;
        istringstream iss(str);
        iss >> choice;

        if (iss.eof() == false) {
            cout << "Non-integer input, please try again." << endl;
        } else if(choice > 2 || choice < 0) {
            cout << "Integer selection out of range, please try again" << endl;
        } else {
            validSelection = true;
        }
    } while (!validSelection);

    othelloGame game (&board);  

    if (choice == 1)
        game.newGame = false;

    bool whiteMovesFirst = false;
    bool cpu1;
    bool cpu2;
    float limit;

    if (game.newGame) {

        cpu1 = checkCPU(1);
        cpu2 = checkCPU(2);

        if (cpu1 || cpu2) {
            limit = getTimeLimit();
        }   

        cout << "New Game\n";
        game.firstMove();

    } else {
        string filename;
        cout << "Give filename of savefile: ";
        cin >> filename;
        game.loadGame(filename, whiteMovesFirst, limit);

        cpu1 = checkCPU(1);
        cpu2 = checkCPU(2);
    }

    heuristicEvaluation h;

    // humanPlayer, playerId, n, symbol 
    player playerOne (!cpu1, 1, board.n,-1, h); // black
    player playerTwo (!cpu2, 0, board.n,1,  h);  // white

    if (cpu1 || cpu2) {
        playerOne.limit = limit;
        playerTwo.limit = limit;
    }

    if (whiteMovesFirst) {
        game.move(playerTwo);
        game.statusUpdate();
    }

    while (!game.complete) {
        game.move(playerOne); // player one moves
        game.move(playerTwo);
        game.statusUpdate(); // updates value of game.complete 
    };  
}