Exemplo n.º 1
0
void vertical_column1(CuTest* tc)
{
  int num_rows = 7;
  int num_columns = 7;
  int array[num_rows][num_columns];
  int answer;
  ct_initialize(num_rows, num_columns, array);

  placeToken(0, 1, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Single 0 in column 1", NO_WINNER_YET, answer);

  placeToken(0, 1, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Two 0s in column 1", NO_WINNER_YET, answer);


  placeToken(0, 1, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Three 0s in column 1", NO_WINNER_YET, answer);


  placeToken(0, 1, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "4 in a row, vertical", 0, answer);
}
Exemplo n.º 2
0
void horizontal_row0(CuTest* tc)
{
  int num_rows = 7;
  int num_columns = 7;
  int array[num_rows][num_columns];
  int answer;
  ct_initialize(num_rows, num_columns, array);

  placeToken(0, 0, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Single 0 in column 0", NO_WINNER_YET, answer);

  placeToken(0, 1, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "0s in columns {0,1}", NO_WINNER_YET, answer);


  placeToken(0, 2, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "0s in columns {0,1, 2}", NO_WINNER_YET, answer);


  placeToken(0, 3, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "4 in a row, horizontal", 0, answer);
}
Exemplo n.º 3
0
void placeToken_recognizes_already_placed_tokens(CuTest *tc) {
  int num_rows = 3;
  int num_columns = 3;
  int array[num_rows][num_columns];
  ct_initialize(num_rows, num_columns, array);

  placeToken(0, 2, num_rows, num_columns, array);
  placeToken(1, 2, num_rows, num_columns, array);

  CuAssertIntEquals_Msg(tc, "Drop 1 into empty column 3", 0, array[num_rows - 1][2]);
  CuAssertIntEquals_Msg(tc, "Drop 1 into empty column 3", 1, array[num_rows - 2][2]);

}
Exemplo n.º 4
0
void placeToken_must_be_in_board(CuTest *tc) {
  int num_rows = 3;
  int num_columns = 3;
  int array[num_rows][num_columns];
  ct_initialize(num_rows, num_columns, array);

  placeToken(0, 3, num_rows, num_columns, array);
  placeToken(0, -1, num_rows, num_columns, array);

  CuAssertIntEquals_Msg(tc, "Must drop into board.", -1, array[num_rows - 1][0]);
  CuAssertIntEquals_Msg(tc, "Must drop into board.", -1, array[num_rows - 1][2]);


}
Exemplo n.º 5
0
Arquivo: main.c Projeto: coreygrubb/GO
// Function to let the user choose the certain location they perfer.
void user_index(int row_index, int column_index, int token)
{
    char valid_input = 'N';
    
    // Player places game piece in a certain row and column.
    while(valid_input == 'N')
    {
        // Allow player 1 to select row and column.
        int row = 0;
        int column = 0;
        
        printf("\nPlace a game piece in a 9x9 grid.\n");
        printf("Row:       ");
        scanf("%d", &row);
        row = row - 1;
        
        printf("Column:    ");
        scanf("%d", &column);
        column = column - 1;
        
        // Checking to see valid row and column index.
        if((row >= 9) || (column >= 9))
        {
            printf("\nInvalid row and/or column index.\n");
        }
        
        else if((row < 0) || (column < 0))
        {
            printf("\nInvalid row and/or column index.\n");
        }
        
        // Let the player know that token is taken.
        else if(placeToken(row, column, token) == 'N')
        {
            printf("\nAlready on the board.\n");
        }
        
        else
        {
            // Place token on board.
            valid_input = 'Y';
            break;
        }
    }
}
Exemplo n.º 6
0
void placeToken_c1(CuTest *tc) {

  int num_rows = 7;
  int num_columns = 7;
  int array[num_rows][num_columns];
  ct_initialize(num_rows, num_columns, array);

  placeToken(1, 3, num_rows, num_columns, array);

  // make sure there is a 1 at the bottom of column 3 and a -1 everywhere else
  CuAssertIntEquals_Msg(tc, "Drop 1 into empty column 3", 1, array[num_rows - 1][3]);
  int r, c;
  for (r = 0; r < num_rows; r++) {
    for (c = 0; c < num_columns; c++) {
      if (r != (num_rows - 1) || c != 3) {
	CuAssertIntEquals_Msg(tc, "Should be empty", EMPTY, array[r][c]);
      }
    }
  }
}
Exemplo n.º 7
0
Arquivo: main.c Projeto: coreygrubb/GO
int main()
{
    int display, rounds, row, column;
    int token = 2;
    char nextRound = 'Y';
    
    // Introduction to the game "GO"
    // Displaying the rules
    game_rules(display);
    printf("\n\n");
    
    // Ask the players how many rounds they would like to play.
    printf("\nHow many rounds would the user like to play?");
    printf("\nRecommended 15-20 rounds.");
    printf("\nRounds:    ");
    scanf("%d", &rounds);
    
    int ctr = 0;
    
    // Print the 9x9 grid
    placeToken(0,0,0);
    printf("\n");
    
    // Declare variable for menu option choice
    int choice = 1;
    
    // Menu - Game options
    while(choice != 0 && ctr < rounds)
    {
        // Tells if player wants to continue into the next round
        if(nextRound == 'Y')
        {
            if(token == 2)
            {
                token = 1;
            }
            else
            {
                token = 2;
            }
        }
        
        // Helps delcare which player's turn is up.
        // Player 1's turn
        if(token == 1)
        {
            printf("\nPlayer #1:\n");
        }
        // Player 2's turn
        else
        {
            printf("\nPlayer #2:\n");
        }
        
        printf("\nGame Options:");
        printf("\n1] Display the rules of the game.");
        printf("\n2] Place a game piece at a certian location.");
        printf("\n0] Exit the game.");
        printf("\nChoice:    ");
        scanf("%d", &choice);
        
        //Reintalize to let user continue.
        nextRound = 'N';
        
        switch(choice)
        {
                //Display the rules of the game.
            case 1:
                game_rules(display);
                printf("\n");
                break;
                
                //Place a game piece at a certain location
            case 2:
                user_index(row, column, token);
                ctr++;
                nextRound = 'Y';
                break;
                
                //Exit the game
            case 0:
                printf("\nExiting Go.\n");
                break;
                
                //Invalid menu choice
            default:
                printf("\nInvalid Menu choice.\n");
                break;
        }
    }
    
    // Tally Score and declare the winner
    int winner = tallyScore();
    if(winner == 1)
    {
        // Player 1 wins
        printf("\nPlayer #1 Wins!!\n");
    }
    
    if(winner == 2)
    {
        // Player 2 wins
        printf("\nPlayer #2 Wins!!\n");
    }
    
    if(winner == 0)
    {
        // Game ended in a tie!
        printf("\nGame ended in a tie!!\n");
    }
}
Exemplo n.º 8
0
void kurmas_test_2(CuTest *tc) {
  int num_rows = 7;
  int num_columns = 7;
  int array[num_rows][num_columns];
  int answer;
  ct_initialize(num_rows, num_columns, array);

  placeToken(1, 0, num_rows, num_columns, array);
  placeToken(0, 0, num_rows, num_columns, array);
  placeToken(0, 0, num_rows, num_columns, array);
  placeToken(0, 0, num_rows, num_columns, array);

  placeToken(0, 1, num_rows, num_columns, array);
  placeToken(1, 1, num_rows, num_columns, array);
  placeToken(1, 1, num_rows, num_columns, array);
  placeToken(1, 1, num_rows, num_columns, array);
  placeToken(0, 1, num_rows, num_columns, array);

  placeToken(1, 2, num_rows, num_columns, array);
  placeToken(0, 2, num_rows, num_columns, array);
  placeToken(0, 2, num_rows, num_columns, array);
  placeToken(0, 2, num_rows, num_columns, array);
  placeToken(1, 2, num_rows, num_columns, array);
  placeToken(0, 2, num_rows, num_columns, array);

  placeToken(0, 3, num_rows, num_columns, array);
  placeToken(1, 3, num_rows, num_columns, array);
  placeToken(1, 3, num_rows, num_columns, array);
  placeToken(1, 3, num_rows, num_columns, array);
  placeToken(0, 3, num_rows, num_columns, array);
  placeToken(1, 3, num_rows, num_columns, array);
  placeToken(0, 3, num_rows, num_columns, array);

  placeToken(0, 6, num_rows, num_columns, array);

  answer = winner(num_rows, num_columns, 5, array);

  CuAssertIntEquals_Msg(tc, "Player 1", -1, answer);
}
Exemplo n.º 9
0
void backward_diagonal(CuTest* tc)
{
 /*
    . . . . . . .
    . . . . . . .
    . . . . . . .
    . . . 0 . . .
    . . 0 1 . . .
    . 0 0 0 . . .
    0 1 1 1 . 1 .
  */

  int num_rows = 7;
  int num_columns = 7;
  int array[num_rows][num_columns];
  int answer;
  ct_initialize(num_rows, num_columns, array);

  /* column 0*/
  placeToken(0, 0, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Step 1", NO_WINNER_YET, answer);

  /* column 1*/
  placeToken(1, 1, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Step 2", NO_WINNER_YET, answer);

  placeToken(0, 1, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Step 3", NO_WINNER_YET, answer);


  /* column 2*/
  placeToken(1, 2, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Step 4", NO_WINNER_YET, answer);

  placeToken(0, 2, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Step 5", NO_WINNER_YET, answer);

  placeToken(1, 5, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Step 6", NO_WINNER_YET, answer);

  placeToken(0, 2, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Step 7", NO_WINNER_YET, answer);

 /* column 3 */
  placeToken(1, 3, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Step 8", NO_WINNER_YET, answer);

  placeToken(0, 3, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Step 9", NO_WINNER_YET, answer);

  placeToken(1, 3, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Step 10", NO_WINNER_YET, answer);

  placeToken(0, 3, num_rows, num_columns, array);
  answer = winner(num_rows, num_columns, 4, array);
  CuAssertIntEquals_Msg(tc, "Step 11 -- Winner!", 0, answer);
}