示例#1
0
void testPlayTurn() {
  int b[2][25] = 
  {
    //MEGLIO NON RADDOPPIARE
    //{0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    //{0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} //PC

    //RICHIESTA DI RADDOPPIO SU 0 A 0
    //{1, 1, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0}, 
    //{0, 2, 2, 3, 0, 3, 2, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} //PC

    //RACE GAME..
    //{0, 0, 0, 0, 2, 5, 2, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}, 
    //{0, 0, 0, 2, 0, 4, 2, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0} //PC
    
    {0, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0},//BLACK (HUMAN) BGV 
    {0, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0}//WHITE (PC)
  };
  
  setBoard((ConstTanBoard)b);
  ms.nCube = 1;
  ms.fCubeOwner = 1;
  ms.fMove = 1;
  ms.fTurn = 1;
  ms.anScore[0] = 0;
  ms.anScore[1] = 0;
  ms.nMatchTo = 1;
  ms.fCrawford = FALSE;

  printf("\n\nTEST TURNO IA...\n");
  printBoard((ConstTanBoard)b);
  //printf("RESIGN: %d\n", askForResignation());
  //printf("DOUBLING: %s\n", askForDoubling()?"YES":"NO");
  int dices[2] = {6, 4};
  int move[8];
  //rollDice(dices);
  printDices(dices);
  evaluateBestMove(dices, move);
  printMove(move);
  printf("AIlevel: %d\n\n", currentAILevel);
}
示例#2
0
void testGenerateMoves() {
  int _b[2][25] =   
  {
    {1, 1, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0}, 
    {0, 2, 2, 3, 0, 3, 2, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} //PC
  };
  
  ConstTanBoard b=ms.anBoard;
  printf("\n\nTEST GENERATE MOVES...\n");
  printBoard((ConstTanBoard)b);
  int dices[2] = {4, 6};
  printDices(dices);
  
  int** moves; 
  int nMoves;

  moves = generateMoves((ConstTanBoard)b, dices[0], dices[1], &nMoves);
  int i=0;
  for (i=0;i<nMoves;i++) {
    printMove(moves[i]);
  }
  printf("MOVES: %d\n", nMoves);
  printf("AIlevel: %d\n\n", currentAILevel);
}
示例#3
0
int main32(void)
{
    int diceArray[C_DICE_COUNT];
    int sum = 0;
	int i; // Adapted for VS2010
    char repeatChar;
    int diceFaceCountArray[C_DICE_FACE_COUNT]; // using index 0 means face = 1.


    printf_s("Welcome to the Yatzy Game!\n\n");
    do
    {

        // Initierar Arrayen med slumptal
        rollDice(C_DICE_COUNT, diceArray);

        // Skriver ut arrayen.
        printDices(C_DICE_COUNT, diceArray);

        // Summerar tärningarna
        sum = sumDice(C_DICE_COUNT, diceArray);

        // Utskrivt
        printf_s("Summa: (");
        for (i = 0; i < C_DICE_COUNT; i++)
        {
            printf_s("%d", diceArray[i]);
            if (i != C_DICE_COUNT - 1)
            {
                printf_s("+");
            }
        }
        printf_s(") : %d\n", sum);


        for (i = 0; i < C_DICE_FACE_COUNT; i++)
        {
            diceFaceCountArray[i] = countDice(C_DICE_COUNT, diceArray, i + 1);
        }


        {
            int pairCount = 0;
            int trissCount = 0;

            for (i = 0; i < C_DICE_FACE_COUNT; i++)
            {
                if (diceFaceCountArray[i] == 2)
                {
                    pairCount++;
                }
                if (diceFaceCountArray[i] == 3)
                {
                    trissCount++;
                }
            }

            if (pairCount > 0)
            {
                printNumAsText(pairCount);
                printf_s(" Pair(s)\n");
            }
            if (trissCount > 0)
            {
                printNumAsText(trissCount);
                printf_s(" Triss\n");
            }
        }


        do
        {
            // Loopar tills man väljer att avsluta eller börja om.

            printf_s("Would you like roll again? (y/n): ");
            scanf_s("%c", &repeatChar, 1);

            // Tömmer resten av In-strömmen från tangentbordet fram till radslut.
            flushRestOfLine();

            if (repeatChar == 'y' || repeatChar == 'n')
            {
                break;
            }
            else
            {
                printf_s("Please enter either y (yes) or n (no)\n");
            }
        } while (1 == 1);
    } while (repeatChar == 'y');



    printf_s("\nThank you for playing the Yatzy Game!\n\n");
    return 0;

} // main
示例#4
0
void gameLoop(struct player players[]){
  int activePlayer = 0;
  int dices[5];
  int selectedSlot, rerollCount;

  initDice();

  do{
    clearScreen();

    rollAllDices(dices);
    rerollCount=0;

    while(rerollCount < 2){
      clearScreen();
      printBoard(players[activePlayer]);

      setColor(GREEN, BLACK);
      printf("\nNumber of re rolls: %i\n\n", rerollCount);
      printDices(dices);

      //User wants to bail early, not using all rerolls
      if(!selectReroll(dices)) break;
      
      rerollCount++;
    }

    clearScreen();
    printDices(dices);

    //The user gets to select a possible slot for his score
    selectedSlot = selectWhereToSave(dices, players[activePlayer]);

    if(selectedSlot != -1){
      //Assign score to the selected slot
      assignScore(&players[activePlayer], dices, selectedSlot);
    }else{
      //If no slots are valid, one has to be elminated
      clearScreen();
      printDices(dices);
      eliminateSlot(&players[activePlayer]);
    }
	
    clearScreen();
    printBoard(players[activePlayer]);

    //Advance to the next player, if all players are done the loop will end
    if(!allPlayersDone(players)){
      do{
	nextPlayersTurn(players, &activePlayer);
      }while(playerDone(players[activePlayer]));

      printf("\n%s it is your turn, press ENTER to play..", players[activePlayer].playername);
      getchar();
    }else{
      break;
    }

  }while(1);

}