Exemple #1
0
int main(void) {
  printf("Running...\n");

  Patterns patterns;
  // patterns.init(patternsFile3x3, patternsFile5x5);

  Board* b = new Board();
  b->init();
  UCTNode::rootState = b;
  UCTNode *node = new UCTNode(1, -1, nullptr);

  GameResult r;
  while (!b->isGameOver(&r)) {
    switch (b->turn) {
     case Black:
      randomMove(&node, b);
      break;
     case White:
      computerMove(&node, b, 0, 500, nullptr); // &patterns);
      break;
     case Empty:
     case OutOfBounds:
     default:
      assert(false);
    }
  }

  delete node;
  delete b;
}
Exemple #2
0
int main() {
    int board[9] = {0,0,0,0,0,0,0,0,0};
    //computer squares are 1, player squares are -1.
    printf("Computer: O, You: X\nPlay (1)st or (2)nd? ");
    int player=0;
    scanf("%d",&player);
    printf("\n");
    unsigned turn;
    for(turn = 0; turn < 9 && win(board) == 0; ++turn) {
        if((turn+player) % 2 == 0)
            computerMove(board);
        else {
            draw(board);
            playerMove(board);
        }
    }
    switch(win(board)) {
        case 0:
            printf("A draw. How droll.\n");
            break;
        case 1:
            draw(board);
            printf("You lose.\n");
            break;
        case -1:
            printf("You win. Inconceivable!\n");
            break;
    }
}
Exemple #3
0
void TicTacGameBoard::newGame()
{
    st = HumansTurn;
    for ( int i=0; i<nBoard*nBoard; i++ )
	btArray->at(i) = TicTacButton::Blank;
    if ( comp_starts )
	computerMove();
    else
	updateButtons();
}
int main() {
  printf("Go MonteCarloAI\n");

  int numSimulations = 0;
  float millaSecondsToThink = 15000;

  auto b = new Board();
  b->init();

  UCTNode *currentNode;
  root = new UCTNode(-1, -1, nullptr);
  UCTNode::rootState = b;
  currentNode = root;

  b->show();

  Patterns patterns;
  // patterns.init(patternsFile3x3, patternsFile5x5);

  GameResult result = None;
  while (!b->isGameOver(&result)) {
    if (b->turn == White) {
      computerMove(&currentNode, b, numSimulations, millaSecondsToThink, nullptr); // &patterns);
    } else {
      // computerMove(&currentNode, b, numSimulations, millaSecondsToThink, nullptr); // &patterns);
      playerMove(&currentNode, b);
      // randomMove(&currentNode, b);
    }
    b->show();
  }

  if (result == Draw) {
    printf("Draw\n");
  } else if (static_cast<Player>(result) == Black) {
    printf("Black Won\n");
  } else {
    printf("White Won\n");
  }

  float score = 0;
  score = b->getTaylorScore(0.5);
  printf("\nScore: %f\n", score);

  delete currentNode;
  delete b;
  return 0;
}
Exemple #5
0
void TicTacGameBoard::buttonClicked()
{
    if ( st != HumansTurn )			// not ready
	return;
    int i = buttons->findRef( (TicTacButton*)sender() );
    TicTacButton *b = buttons->at(i);		// get piece that was pressed
    if ( b->type() == TicTacButton::Blank ) {	// empty piece?
	btArray->at(i) = TicTacButton::Circle;
	updateButtons();
	if ( checkBoard( btArray ) == 0 )	// not a winning move?
	    computerMove();
	int s = checkBoard( btArray );
	if ( s ) {				// any winners yet?
	    st = s == TicTacButton::Circle ? HumanWon : ComputerWon;
	    emit finished();
	}
    }
}
Exemple #6
0
int main(int argc, char** argv) {
	startNewGame();
	while (1) {
		int move;
		printf("Move? ");
		scanf("%d", &move);
	       
		playerMove(move);
 
		printGameState(globalState);
 
		checkWin(globalState);
 
		computerMove(LOOK_AHEAD);
 
		printGameState(globalState);
 
		checkWin(globalState);
	}
 
	freeGameState(globalState);
 
	return 0;
}
int main(int argc, char const *argv[])
{
    int x = 0, y = 0;
    char done = '-';
    char mainboard[3][3];
    initBoard(mainboard);
    do
    {
        showBoard(mainboard);
        playerMove(mainboard);
        done = boardCheck(mainboard, 'X');
        if (done != '-') break;
        computerMove(mainboard);
        done = boardCheck(mainboard,'O');
        if(done!='-') break;
    }
    while (done == '-');
    if (done == 'X')
        printf("You won\n");
    else
        printf("Computer Won\n");
    showBoard(mainboard);
    return 0;
}
Exemple #8
0
int main(void)
{
  BOOLEAN myturn;
  myturn = TRUE;
  drawBoard();
  srand(time(NULL));
  rand();
  do
  {
    switch (status())
    {
      case WIN:
      case LOSE:
      case DRAW:
      init();
      drawBoard();
      if (myturn)
      {
        makeMove(COMPUTER,(2+rand()%4),square);
      }
      myturn = !myturn;
      drawPiece();
    }
    textcolor(4);
    gotoxy(1,20);
    cprintf("Your Turn, Please.\n");
    getHumanMove();
    gotoxy(1,20);
    textcolor(4);
    switch (status())
    {
      case WIN:
        cprintf(WIN_MESSAGE);
        getch();
      break;
      case LOSE:
        cprintf(LOSE_MESSAGE);
        getch();
      break;
      case DRAW:
        cprintf(DRAW_MESSAGE);
        getch();
        break;
      default:/*OK*/
        if(computerMove())
        {
          gotoxy(1,20);
          drawPiece();
          gotoxy(1,20);
          switch (status())
          {
            case WIN:
              cprintf(WIN_MESSAGE);
              getch();
            break;
            case LOSE:
              cprintf(LOSE_MESSAGE);
              getch();
            break;
            case DRAW:
              cprintf(DRAW_MESSAGE);
              getch();
            break;
          }
        }
    }
  }
  while(TRUE);
}