Пример #1
0
//helper function to simulate winning moves
void winning_move(int* moves, int expected_winner){
	int i = 0;
	while((winnerIs(g_board) == 0) && validMovesLeft(g_board)){
		if(getCurrentPlayer(g_board) == PLAYER_ONE){
			makeMove(g_board, moves[i]);
			++i;
		} else {
			makeMove(g_board, getReasonedMove(g_board));
		}
	}
	assert_int_equal(expected_winner, winnerIs(g_board));
	/*
 * assert_true(winnerIs(g_board) == 0);

	makeMove(g_board, 0); //player one moves
	makeMove(g_board, 1); //player two moves
	assert_true(winnerIs(g_board) == 0);

	makeMove(g_board, 0); //player one moves
	makeMove(g_board, 2); //player two moves
	assert_true(winnerIs(g_board) == 0);

	makeMove(g_board, 0); //player one moves
	makeMove(g_board, 3); //player two moves

	assert_true(winnerIs(g_board) == 0);
	makeMove(g_board, 0); //player one moves
	makeMove(g_board, 3); //player two moves

	assert_int_equal(expected_winner, winnerIs(g_board));
*/
}
Пример #2
0
void test_diagonal_win(){
	assert_true(winnerIs(g_board) == 0);

	makeMove(g_board, 0); //player one moves
	makeMove(g_board, 1); //player two moves
	assert_true(winnerIs(g_board) == 0);

	makeMove(g_board, 1); //player one moves
	makeMove(g_board, 2); //player two moves
	assert_true(winnerIs(g_board) == 0);

	makeMove(g_board, 3); //player one moves
	makeMove(g_board, 2); //player two moves

	assert_true(winnerIs(g_board) == 0);
	makeMove(g_board, 2); //player one moves
	makeMove(g_board, 3); //player two moves
	
	assert_true(winnerIs(g_board) == 0);
	makeMove(g_board, 4); //player one moves
	makeMove(g_board, 3); //player two moves

	assert_true(winnerIs(g_board) == 0);
	makeMove(g_board, 3); //player one moves

	assert_int_equal(PLAYER_ONE, winnerIs(g_board));
}
Пример #3
0
/* winnerIs should accept scores of four in horizontal, vertical and both
 * diagonal directions. Should return the correct winning player and IFF there
 * are four points in a row. */
void test_winnerIs() {
  board_type *board = createBoard(X, Y);
  int i, j;

  CU_ASSERT_EQUAL(winnerIs(board), 0);

  for(i = 0; i < 4; i++) {
    board->current_player = PLAYER_ONE;
    makeMove(board, i);
  }

  CU_ASSERT_EQUAL(winnerIs(board), PLAYER_ONE);

  for(i = 0; i < 4; i++)
    undoMove(board);

  for(i = 0; i < 4; i++) {
    board->current_player = PLAYER_TWO;
    makeMove(board, i);
  }

  CU_ASSERT_EQUAL(winnerIs(board), PLAYER_TWO);

  for(i = 0; i < 4; i++)
    undoMove(board);

  /* Bottom left to top right diagonal */
  for(i = 2; i < 5; i++) {
    for(j = i; j < 5; j++) {
      board->current_player = PLAYER_TWO;
      makeMove(board, i);
    }
  }

  for(i = 2; i < 6; i++) {
      board->current_player = PLAYER_ONE;
      makeMove(board, i);
  }

  CU_ASSERT_EQUAL(winnerIs(board), PLAYER_ONE);

  /* Bottom left to top right diagonal */
  for(i = 2; i < 6; i++) {
    for(j = i; j < 6; j++)
      undoMove(board);
  }

  /* Bottom left to top right diagonal */
  for(i = 2; i < 5; i++) {
    for(j = 5; j > i; j--) {
      board->current_player = PLAYER_ONE;
      makeMove(board, i);
    }
  }

  for(i = 2; i < 6; i++) {
      board->current_player = PLAYER_TWO;
      makeMove(board, i);
  }

  CU_ASSERT_EQUAL(winnerIs(board), PLAYER_TWO);

  undoMove(board);

  CU_ASSERT_EQUAL(winnerIs(board), 0);

  free(board);
}
Пример #4
0
int main(){

	 int bets = 0, pot = 0;

	 Deck game_deck = get_new_Deck();
	 printf("\n\n");
	 hBorder();	 
	 printf("\n\n");
	 welcomeSign();
	 hBorder();	 
	 welcome();
	 printf("\n");
	 hBorder();
	 printf("\n");
	 printf("\n");

	 Player one = player_init(getName(), getRupies());
	 printf("Hi %s, you have %i rupies\n",one.name, one.rupies);
	 Player two = player_init("Link", one.rupies);
	 Player three = player_init("Mario", one.rupies);
	 Player four = player_init("Taloon", one.rupies);
	 getStatus(&two);
	 getStatus(&three);
	 getStatus(&four);
	 printf("\n\n");
	 hBorder();	 

	 Player *table[NUM_PLAYERS];
	 table[0] = &one;
	 table[1] = &two;
	 table[2] = &three;
	 table[3] = &four;

	 int gamenumber = 1;
	 int gamesplayed = 0;
	 int gameStatus = 1;
	 while(gamenumber == 1){

		  if(gameStatus == 1){ 
				if(gamesplayed != 0){
					 printf("\n\n");
					 welcomeSign();
					 hBorder();	 
				}
				gamesplayed++;
				printf("\n\nREADY -- Here we go...\n\n");
				shuffle(&game_deck, DECK_SIZE);
				first_Deal(&game_deck, table, NUM_PLAYERS);
				gamescene(3, table);

				print_Hand(table, 1);
				isHand(one.hand);
				bets = betAmount(&one);
				printf("%s, bets %i rupies\n",one.name, bets);
				pot += bets;
				/*	cpuBIGACTION(table, &bets, &game_deck);

#pragma omp parallel num_threads(4)
int z;
tid = omp_get_thread_number();
for(z=1;z<NUM_PLAYERS;z++){
if(tid == 1){
				 */		  pot += cpuActions(&game_deck, &two, &one, bets); 
				/*	 }
					 if(tid == 1){
				 */		  
				printf("...hmm...yea...\n");
				pot += cpuActions(&game_deck, &three, &one, bets); 
				/*	 }
					 if(tid == 1){
				 */		  
				printf("...uhhh...ok...\n");
				pot += cpuActions(&game_deck, &four, &one, bets); 
				/*	 }
					 }*/
				hBorder();
				banter(table);
				playersLeft(table, &gameStatus);
		  }
		  if(gameStatus ==1){
				print_Hand(table, 1);
				print_Options();
				isHand(one.hand);

				Deck MC_Deck = create_Monte(&one);
				monteSuggest(monte_Analysis(&MC_Deck, &one));
				printTextReco(&one);

				newCards(&game_deck,&one);
				print_Hand(table, 1);
				isHand(one.hand);
				printf("\n\n");
				bets = betAmount(&one);
				pot += bets;
				pot += cpuBets(&two, &one, bets);
				pot += cpuBets(&three, &one, bets);
				pot += cpuBets(&four, &one, bets);


				playersLeft(table, &gameStatus);
		  }
		  hBorder();
		  printResults(table);
		  evaluateHands(table); 
		  tableCompareTo(table);

		  winnerIs(table, pot);
		  hBorder();
		  printf("\n");
		  banter(table);
		  getTableStatus(table);

		  gamenumber = playgame();
		  printf("\n\n\n\n");
		  bets = 0;
		  pot = 0;
		  tableRefresh(table);
	 }
	 return 0;
}