Example #1
0
int main(int argc, char** argv) {
    char board[26][26];
    int n;
    int numberOfMoves = 0;
    int *moves = &numberOfMoves;
    char computerColour, currentColour;
    printf("Enter the board dimension: ");
    scanf("%d", &n);
    makeBoard(board, n);
    printf("Computer plays (B/W) : ");
    scanf(" %c", &computerColour);
    currentColour = 'B';
    char nextColour = 'W';
    char tempColour;
    bool gameOver = 0;
    char rowMove, colMove;
    
    printBoard(board, n);
    
    while(!gameOver){
        if(movesAvailable(board, n, currentColour)){
            if(currentColour == computerColour){
                decideMove(board, n, computerColour, moves);
                numberOfMoves++;
            }
            else{
                printf("Enter move for colour %c (RowCol): ", currentColour);
                scanf(" %c%c", &rowMove, &colMove);
                if(checkLegalInPosition(board, n, rowMove - 'a', colMove - 'a', currentColour)){
                    makeMove(board, n, rowMove - 'a', colMove - 'a', currentColour);
                    numberOfMoves++;
                }
                else{
                    printf("Invalid move.\n");
                    printf("%c player wins.\n", findWinner(board, n));
                    return 0;
                }
            }
            printBoard(board, n);
            
        }
        else{
            printf("%c player has no valid move.\n", currentColour);
        }
        
        tempColour = currentColour;
        currentColour = nextColour;
        nextColour = tempColour;
        
        if(!movesAvailable(board, n, 'B') && !movesAvailable(board, n, 'W')){
            printf("%c player wins.\n", findWinner(board, n));
            gameOver = true;
        }
        
    }
    
    
    return (EXIT_SUCCESS);
}
Example #2
0
void testBlank(void) {
    HunterView gameState;

    {
        playerMessage messages[1] = {""};
        printf("Test: blank game.\n");
        printf("creating hunterview.\n");
        gameState = newHunterView("",messages);
        printf("deciding move.\n");
        decideMove( gameState );
        printf("disposing.\n");
        disposeHunterView( gameState );
        printf("Test passed\n");
    }
}
Example #3
0
void testMovesRound1(void) {
    HunterView gameState;

    {
        playerMessage messages[7] = {""};
        printf("Test1: Round 1 hunter 2 move. Testing his connected locs.\n");
        printf("creating hunterview.\n");
        gameState = newHunterView("GGW.... SGA.... HAT.... MMA.... DBO.V.. GGW.... SKL....",messages);
        printf("deciding move.\n");
        decideMove( gameState );
        printf("disposing.\n");
        disposeHunterView( gameState );
        printf("Test passed\n");

        printf("Test2: Round 1 hunter 2 move. Testing his connected locs.\n");
        printf("creating hunterview.\n");
        gameState = newHunterView("GCD.... SBE.... HST.... MMA.... DC?.V.. GKL.... SKL.... HST....",messages);
        printf("deciding move.\n");
        decideMove( gameState );
        printf("disposing.\n");
        disposeHunterView( gameState );
        printf("Test passed\n");
    }
    {
        playerMessage messages[7] = {""};
        printf("Testing fail round 2, hunter 2 trying to move illegally to CD\n");
        gameState = newHunterView("GCD.... SBE.... HST.... MMA.... DKL.V.. GKLVD.. SKLD...",messages);
        decideMove(gameState);
        disposeHunterView(gameState);
        printf("Test passed!\n");
        printf("latest play is %s\n",latestPlay);
    }
    /*
    {
        playerMessage messages2[] = {
        "camping",
        "",
        "",
        "",
        "+++Mr. Jelly! Mr. Jelly!+++",
        "I'm camping MAN!!!",
        "",
        "",
        "pn\u001a\thF\u001a\t\u0003",
        "+++Mr. Jelly! Mr. Jelly!+++",
        "I'm camping MAN!!!",
        "VR",
        "VR",
        "VR",
        "+++Oneoneoneoneoneoneone+++",
        "I'm camping MAN!!!"
      };
        printf("Testing player 2 fail case round 5. Tried moving from Liverpool -> London\n");
        gameState = newHunterView("GCD.... SBE.... HST.... MMA.... DGA.V.. GCD.... SBE.... HST.... MMA.... DBCT... GCD.... SKL.... HMU.... MMA.... DHIT... GCD.... SGAV... HVI.... MMA.... DD1T... GCD.... SGA.... HBD.... MMA.... DCNT... GCD.... SGA.... HKL.... MMA.... DC?T... GCD.... SGA.... HGA.... MMA.... DBS.... GCD.... SGA.... HGA.... MMA.... DS?..M. GCD.... SGA.... HGA.... MMA.... DSAT.M. GCD.... SGA.... HGA.... MMA.... DD2..M. GCD.... SGA.... HCNT... MMA.... DTS.... GCD.... SGA.... HCN.... MMA.... DCGT.M. GCD.... SGA.... HBS.... MMA.... DHIT... GCD.... SGA.... HBS.... MMA.... DMS.... GCD.... SGA.... HIO.... MMA.... DS?..M. GCD.... SGA.... HIO.... MMA.... DEC.... GCD.... SGA.... HTS.... MMA.... DLOT... GCD.... SGA.... HTS.... MMA.... DD1T.M. GCD.... SGA.... HTS.... MMA.... DHIT.M. GCD.... SGA.... HMS.... MMA.... DSWT... GCD.... SGA.... HMS.... MMA.... DS?.... GCD.... SGA.... HAO.... MMA.... DLVT... GCD.... SGA.... HAO.... MMA.... DC?T.M. GCD.... SGA.... HAO.... MMA.... DD5T.M. GCD.... SGA.... HAO.... MMA.... DPLT.M. GCD.... SGA.... HIS.... MMA.... DS?..M. GCD.... SGA.... HIS.... MMA.... DC?.V.. GCD.... SGA.... HLVT... MMA.... DC?T... GCD.... SGA.... HLV.... MMA.... DC?T.M. GCD.... SGA.... HLV.... MMA.... DD1T.M. GCD.... SGA....",messages2);
        decideMove(gameState);
        printf("latest play is %s\n",latestPlay);
        disposeHunterView(gameState);
        printf("Congrats, test should pass\n");
    } */
    {
        playerMessage messages[13] = {""};
        printf("Testing player 2 fail case round 5. Tried moving from Madrid -> Bordeaux\n");
        gameState = newHunterView("GCD.... SBE.... HST.... MMA.... DGA.V.. GCD.... SBE.... HST.... MMA.... DC?T... GCD.... SKL.... HMU....", messages);
        decideMove(gameState);
        printf("latest play is %s\n",latestPlay);
        disposeHunterView(gameState);
        printf("Congrats, test should pass\n");
    }
    {
        playerMessage messages[13] = {""};
        printf("Testing player 2 fail case round 5. Player One is making segFaults! player at Vienna\n");
        gameState = newHunterView("GCD.... SBE.... HST.... MMA.... DGA.V.. GCD.... SBE.... HST.... MMA.... DC?T... GCD.... SKL.... HMU.... MMA.... DC?T... GCD.... SGAV... HVI.... MMA.... DD1T... GCD.... SGA....",messages);
        decideMove(gameState);
        printf("latest play is %s\n",latestPlay);
        disposeHunterView(gameState);
        printf("Congrats, test should pass\n");
    }
    {
        playerMessage messages[31] = {""};
        printf("Testing player 1 fail case from game 303 round 6\n");
        gameState = newHunterView("GCD.... SBE.... HST.... MMA.... DCG.V.. GCD.... SBE.... HST.... MMA.... DS?.... GCD.... SSA.... HGE.... MAL.... DS?.... GCD.... SIO.... HMR.... MMS.... DC?T... GCD.... STS.... HMS.... MCGV... DC?T... GCD.... SCG.... HCG.... MCG.... DC?T... GCD....",messages);
        decideMove(gameState);
        printf("latest play is %s\n",latestPlay);
        disposeHunterView(gameState);
        printf("Congrats, this segfaulted in the game\n");
    }
    {
        playerMessage messages[32] = {""};
        printf("Testing player 2 fail case from game 303 round 6\n");
        gameState = newHunterView("GCD.... SBE.... HST.... MMA.... DCG.V.. GCD.... SBE.... HST.... MMA.... DS?.... GCD.... SSA.... HGE.... MAL.... DS?.... GCD.... SIO.... HMR.... MMS.... DC?T... GCD.... STS.... HMS.... MCGV... DC?T... GCD.... SCG.... HCG.... MCG.... DC?T... GCD.... SCG....",messages);
        decideMove(gameState);
        printf("latest play is %s\n",latestPlay);
        disposeHunterView(gameState);
        printf("Congrats, this segfaulted in the game\n");
    }
    {
        playerMessage messages[26] = {""};
        printf("Testing player 1 fail case from game 39 round 9. player making illegal move from Constanta (but was (TD) so health would be -3)\n");
        gameState = newHunterView("GCD.... SBE.... HST.... MMA.... DBS.... GCD.... SBE.... HST.... MMA.... DCNT... GCD.... SCNTD.. HMU.... MAL.... DC?T... GCD.... SCN.... HZA.... MMS.... DD2T... GCD.... SCNTD.. HSZ.... MTS.... DC?T... GCD....",messages);
        decideMove(gameState);
        printf("HIS LATEST PLAY IS %s\n",latestPlay);
        disposeHunterView(gameState);
    }
    {
        playerMessage messages[152] = {""};
        printf("Testing player 2 fail case from game 199. player returning \"\" for move. Player in Tyrrhehian Sea.\n");
        gameState = newHunterView("GCD.... SBE.... HST.... MMA.... DAL.V.. GCD.... SBE.... HST.... MMA.... DC?T... GCD.... SSA.... HGE.... MALV... DSNT... GCD.... SIO.... HMR.... MAL.... DS?.... GCD.... STS.... HMS.... MAL.... DNAT... GCD.... SMS.... HAL.... MAL.... DHIT... GCD.... SAL.... HAL.... MAL.... DCFT... GCD.... SAL.... HAL.... MAL.... DTOT.M. GCD.... SMA.... HSNT... MSN.... DD1T... GCD.... SMA.... HSN.... MSN.... DBAT... GCD.... SBO.... HBB.... MBB.... DSRT.M. GCD.... SBO.... HBB.... MBB.... DHIT.M. GCD.... SCFT... HBO.... MBO.... DMAT... GCD.... SCF.... HBO.... MBO.... DC?.VM. GCD.... SCF.... HBO.... MBO.... DCAT.M. GCD.... STO.... HSRTT.. MSR.... DD1T.M. GCD.... SSR.... HSR.... MSR.... DAO.... GCD.... SSR.... HSR.... MSR.... DS?.... GCD.... SMAT... HMA.... MMA.... DCGT... GCD.... SMA.... HMA.... MMA.... DHIT.V. GCD.... SCATT.. HCA.... MCA.... DTS.... GCD.... SCA.... HCA.... MCA.... DROT... GCD.... SAO.... HAO.... MAO.... DD1T... GCD.... SAO.... HAO.... MAO.... DBIT... GCD.... SMS.... HMS.... MMS.... DNPT.M. GCD.... SMS.... HMS.... MMS.... DC?T.M. GCD.... STS.... HTS.... MTS.... DTP.V.. GCDVD.. STS.... HTS.... MTS.... DC?T.M. GCD.... STS.... HTS.... MTS.... DC?T.M. GCD.... STS.... HTS.... MTS.... DD1T.M. GCD.... STS....",messages);
        decideMove(gameState);
        printf("HIS LATEST PLAY IS (%s)\n",latestPlay);
        disposeHunterView(gameState);
    }
    {
        playerMessage messages[149] = {""};
        printf("Testing player 3 fail case from game 199. player seg faulting. Player in Tyrrhehian Sea.\n");
        gameState = newHunterView("GCD.... SBE.... HST.... MMA.... DAL.V.. GCD.... SBE.... HST.... MMA.... DC?T... GCD.... SSA.... HGE.... MALV... DSNT... GCD.... SIO.... HMR.... MAL.... DS?.... GCD.... STS.... HMS.... MAL.... DNAT... GCD.... SMS.... HAL.... MAL.... DHIT... GCD.... SAL.... HAL.... MAL.... DCFT... GCD.... SAL.... HAL.... MAL.... DTOT.M. GCD.... SMA.... HSNT... MSN.... DD1T... GCD.... SMA.... HSN.... MSN.... DBAT... GCD.... SBO.... HBB.... MBB.... DSRT.M. GCD.... SBO.... HBB.... MBB.... DHIT.M. GCD.... SCFT... HBO.... MBO.... DMAT... GCD.... SCF.... HBO.... MBO.... DC?.VM. GCD.... SCF.... HBO.... MBO.... DCAT.M. GCD.... STO.... HSRTT.. MSR.... DD1T.M. GCD.... SSR.... HSR.... MSR.... DAO.... GCD.... SSR.... HSR.... MSR.... DS?.... GCD.... SMAT... HMA.... MMA.... DCGT... GCD.... SMA.... HMA.... MMA.... DHIT.V. GCD.... SCATT.. HCA.... MCA.... DTS.... GCD.... SCA.... HCA.... MCA.... DROT... GCD.... SAO.... HAO.... MAO.... DD1T... GCD.... SAO.... HAO.... MAO.... DBIT... GCD.... SMS.... HMS.... MMS.... DC?T.M. GCD.... SMS.... HMS.... MMS.... DC?T.M. GCD.... STS.... HTS.... MTS.... DTP.V.. GCDVD.. STS.... HTS.... MTS.... DC?T.M. GCD.... STS.... HTS.... MTS.... DC?T.M. GCD.... STS.... HTS....",messages);
        decideMove(gameState);
        printf("HIS LATEST PLAY IS (%s)\n",latestPlay);
        disposeHunterView(gameState);
    }
    {
        playerMessage messages[140] = {""};
        printf("Testing player 1 fail case from game 199. player seg faulting. Player in Tyrrhehian Sea.\n");
        gameState = newHunterView("GCD.... SBE.... HST.... MMA.... DAL.V.. GCD.... SBE.... HST.... MMA.... DC?T... GCD.... SSA.... HGE.... MALV... DSNT... GCD.... SIO.... HMR.... MAL.... DS?.... GCD.... STS.... HMS.... MAL.... DNAT... GCD.... SMS.... HAL.... MAL.... DHIT... GCD.... SAL.... HAL.... MAL.... DCFT... GCD.... SAL.... HAL.... MAL.... DTOT.M. GCD.... SMA.... HSNT... MSN.... DD1T... GCD.... SMA.... HSN.... MSN.... DBAT... GCD.... SBO.... HBB.... MBB.... DSRT.M. GCD.... SBO.... HBB.... MBB.... DHIT.M. GCD.... SCFT... HBO.... MBO.... DMAT... GCD.... SCF.... HBO.... MBO.... DC?.VM. GCD.... SCF.... HBO.... MBO.... DCAT.M. GCD.... STO.... HSRTT.. MSR.... DD1T.M. GCD.... SSR.... HSR.... MSR.... DAO.... GCD.... SSR.... HSR.... MSR.... DS?.... GCD.... SMAT... HMA.... MMA.... DCGT... GCD.... SMA.... HMA.... MMA.... DHIT.V. GCD.... SCATT.. HCA.... MCA.... DTS.... GCD.... SCA.... HCA.... MCA.... DC?T... GCD.... SAO.... HAO.... MAO.... DD1T... GCD.... SAO.... HAO.... MAO.... DC?T... GCD.... SMS.... HMS.... MMS.... DC?T.M. GCD.... SMS.... HMS.... MMS.... DC?T.M. GCD.... STS.... HTS.... MTS.... DTP.V.. GCDVD..",messages);
        decideMove(gameState);
        printf("HIS LATEST PLAY IS (%s)\n",latestPlay);
        disposeHunterView(gameState);
    }
}