예제 #1
0
/* Play a game of tic-tac-toe */
void Game()
{
    Square_Type Player;
    char Answer[String_Length];
    Board_Type Board;
    int Move_Nbr = 1;

    Initialize(Board);

	Player = HUMANPIECE;
    /*printf("\nDo you want to move first? ");
    scanf_s("%s", Answer);
    if (toupper(Answer[0]) == 'Y')
		Player = 'O';
    else
		Player = 'X';
	*/

    while(Winner(Board) == ' ')
	{
		Print(Board);
		Move(Board, Player, Move_Nbr);
		Player = Other(Player);
		Move_Nbr++;
    }
    Print(Board);

	printf("Game over: ");
    if (Winner(Board) != 'C')
		printf("%s wins!\n", (Winner(Board) == COMPPIECE) ? "computer" : "human");
    else
		printf("draw!\n");
}
// ----------------------------------------------------
// CNoughtsAndCrossesEngine::MakeHumanMoveL(TUint aRow, TUint aColumn)
// ----------------------------------------------------
//
TBool CNoughtsAndCrossesEngine::MakeHumanMoveL(TUint aRow, TUint aColumn)
	{
	if( aRow>=BOARD_SIZE    || aRow<0 ||
        aColumn>=BOARD_SIZE || aColumn<0 )
        {
        return EFalse;
        }
	
	if (iBoard[aRow][aColumn] != ENone)
		{
		return EFalse;
		}

	if (iPlayerToGo == iComputerPlayer) return EFalse;

	iBoard[aRow][aColumn] = iHumanPlayer;
	if (iObserver) iObserver->HandleMove (iHumanPlayer, aRow, aColumn);
	iPlayerToGo = iComputerPlayer;

    if (Winner())
		{
		if (iObserver) iObserver->HandleWinnerL(ETrue, 
			winningRowStartIndex, 
			winningColumnStartIndex,
			winningRowEndIndex, 
			winningColumnEndIndex);
		}

	return ETrue;
	}
예제 #3
0
SgEmptyBlackWhite DfpnSolver::StartSearch(DfpnHashTable& hashTable, 
                                          PointSequence& pv,
                                          const DfpnBounds& maxBounds)
{
    m_aborted = false;
    m_hashTable = &hashTable;
    m_numTerminal = 0;
    m_numMIDcalls = 0;
    m_generateMoves = 0;
    m_totalWastedWork = 0;
    m_prunedSiblingStats.Clear();
    m_moveOrderingPercent.Clear();
    m_moveOrderingIndex.Clear();
    m_deltaIncrease.Clear();
    m_checkTimerAbortCalls = 0;

    // Skip search if already solved
    DfpnData data;
    if (TTRead(data) && data.m_bounds.IsSolved())
    {
        SgDebug() << "Already solved!\n";
        const SgEmptyBlackWhite toPlay = GetColorToMove();
        SgEmptyBlackWhite w = Winner(data.m_bounds.IsWinning(), toPlay);
        GetPVFromHash(pv);
        SgDebug() << SgEBW(w) << " wins!\n";
        WriteMoveSequence(SgDebug(), pv);
        return w;
    }

    m_timer.Start();
    DfpnHistory history;
    MID(maxBounds, history);
    m_timer.Stop();

    GetPVFromHash(pv);
    SgEmptyBlackWhite winner = SG_EMPTY;
    if (TTRead(data) && data.m_bounds.IsSolved())
    {
        const SgEmptyBlackWhite toPlay = GetColorToMove();
        winner = Winner(data.m_bounds.IsWinning(), toPlay);
    }
    PrintStatistics(winner, pv);

    if (m_aborted)
        SgWarning() << "Search aborted.\n";
    return winner;
}
예제 #4
0
void Play(int *value)
{
  int c;
  int output = 3; // Set default output value to "Exit"
  // Create new window
  WINDOW *game_win;
  game_win = newwin(15,50,4,4);
  keypad(game_win, TRUE);           // Enable keyboard input
  box(game_win, 0, 0);              // Put a box around the wimdow
  // Add title
  print_in_middle(game_win, 1, 0, 50, "THE GAME", COLOR_PAIR(1));
  mvwaddch(game_win, 2, 0, ACS_LTEE);
  mvwhline(game_win, 2, 1, ACS_HLINE, 48);
  mvwaddch(game_win, 2, 39, ACS_RTEE);
  //sleep(500);
  //Add text
  mvwaddstr(game_win, 2, 2, "This is it, the faith of the whole world is in");
  //sleep(500);
  mvwaddstr(game_win, 3, 2, "your hands. You are the only one who has the");
  //sleep(500);
  mvwaddstr(game_win, 4, 2, "power to defeat evil forces and save the human");
  mvwaddstr(game_win, 5, 2, "kind.");
  //sleep(500);
  mvwaddstr(game_win, 5, 7, "... or DESTROY IT!!!");
  //sleep(500);
  mvwaddstr(game_win, 7, 2, "The power is in your hands. Take the controller");
  mvwaddstr(game_win, 8, 2, "and make your choise:");
  mvwaddstr(game_win, 9, 4, "press A");
  mvwaddstr(game_win, 9, 16, "press B");
  wrefresh(game_win);              // Refres the window

  bool done = false;
  bool win = false;
  // Wait for correct user input
  while(!done && (c = wgetch(game_win)) != 'q')
  {
      //To do:
      //Choose wining button at random
      //For now:
      if (c == 'a' || c == 'A')
      {
        win = true;
        done = true;
      }
      if (c == 'b' || c == 'B')
      {
        win = false;
        done = true;
      }
  }
  // Destroy the window
  endwin();
  // Salute the winner or admit the looser
  if (win)
    Winner(&output);
  else
    Looser(&output);
  *value = output;
}
예제 #5
0
파일: main.cpp 프로젝트: enunes/mazerush
void checkForWinners(void)
{
    for (unsigned int i=0; i<Player_List.size(); ++i) {
        PlayerBase *iPlayer = Player_List[i];
        if (iPlayer->finished() && !finishedPlayers[i]) {
            winners.push_back(Winner(i, Maze_Timer));
            finishedPlayers[i] = winners.size();
            if (i==(unsigned int)humanIndex) {
                toggleCameraButton->show = true;
            }
        }
    }
}
// ----------------------------------------------------
// CNoughtsAndCrossesEngine::CanMove()
// Return ETrue if move is valid
// ----------------------------------------------------
//
TBool CNoughtsAndCrossesEngine::CanMove()
	{
	if (Winner()) return EFalse;

	// Checks for blank spaces...
	for (int i = 0; i < BOARD_SIZE; ++i)
	{
		for (int j = 0; j < BOARD_SIZE; ++j)
		{
			if (iBoard[i][j] == ENone) return ETrue;
		}
	}
	return EFalse;
	}
예제 #7
0
// Set the Board, Pawns, and determine if a winner is available.
int main()
{
	int board[9][8] = {0}, turn = 2, pawn[2] = {12};
	set_defaults(board);
	while (Winner(pawn[1], pawn[2]))
	{
		print_board(board);
		get_co(board, turn, pawn);
		if (turn == 2)
			turn = 1;
		else
			turn = 2;
	}
	scanf("asd");
}
예제 #8
0
파일: 2048.c 프로젝트: jhaenchen/2r11-2048
int main(int argc, char const *argv[])
{
	initscr();
	raw();
	noecho();
	curs_set(0);
	keypad(stdscr,TRUE);
	getmaxyx(stdscr,row,col);
	srand(time(NULL));
	if (gameinit())
		Winner();
	else
		Loser();
	getch();
	endwin();
	return 0;
}
// ----------------------------------------------------
// CNoughtsAndCrossesEngine::RunL()
// CTimer
// ----------------------------------------------------
//
void CNoughtsAndCrossesEngine::RunL()
	{
	iBoard[iComputerMoveRow][iComputerMoveColumn] = iComputerPlayer;
	iObserver->HandleMove (iComputerPlayer, iComputerMoveRow, iComputerMoveColumn);
	iPlayerToGo = iHumanPlayer;

	if (Winner())
		{
		if (iObserver)
			{
			iObserver->HandleWinnerL(EFalse, 
				winningRowStartIndex, 
				winningColumnStartIndex,
				winningRowEndIndex, 
				winningColumnEndIndex);
			}
		}
	}
예제 #10
0
/* Return the score of the best move found for a board
   The square to move to is returned in *Square */
int Best_Move(Board_Type Board, Square_Type Player, int *Square, int Move_Nbr, int Alpha, int Beta)
{
    int Best_Square = -1;
    int Moves = 0;
    int I;
    Move_Heuristic_Type Move_Heuristic[Squares];

    Total_Nodes++;

    /* Find the heuristic for each move and sort moves in descending order */
    for (I = 0; I < Squares; I++)
	{
		if (Board[I] == Empty)
		{
			int Heuristic;
			int J;
			Play(Board, I, Player);
			Heuristic = Evaluate(Board, Player);
			Play(Board, I, Empty);
			for (J = Moves-1; J >= 0 && Move_Heuristic[J].Heuristic < Heuristic; J--)
			{
				Move_Heuristic[J + 1].Heuristic = Move_Heuristic[J].Heuristic;
				Move_Heuristic[J + 1].Square = Move_Heuristic[J].Square;
			}
			Move_Heuristic[J + 1].Heuristic = Heuristic;
			Move_Heuristic[J + 1].Square = I;
			Moves++;
		}
    }

    for (I = 0; I < Moves; I++)
	{
		int Score;
		int Sq = Move_Heuristic[I].Square;
		Square_Type W;

		/* Make a move and get its score */
		Play(Board, Sq, Player);

		W = Winner(Board);
		if (W == 'X')
			Score = (Maximum_Moves + 1) - Move_Nbr;
		else if (W == 'O')
			Score = Move_Nbr - (Maximum_Moves + 1);
		else if (W == 'C')
			Score = 0;
		else
			Score = Best_Move(Board, Other(Player), Square, Move_Nbr + 1, Alpha, Beta);

		Play(Board, Sq, Empty);

		/* Perform alpha-beta pruning */
		if (Player == 'X')
		{
			if (Score >= Beta)
			{
				*Square = Sq;
				return Score;
			}
			else if (Score > Alpha)
			{
				Alpha = Score;
				Best_Square = Sq;
			}
		}
		else
		{
			if (Score <= Alpha)
			{
				*Square = Sq;
				return Score;
			}
			else if (Score < Beta)
			{
				Beta = Score;
				Best_Square = Sq;
			}
		}
	}
    *Square = Best_Square;
    if (Player == 'X')
		return Alpha;
    else
		return Beta;
}