Example #1
0
	void swapIfEnabled(Rucksack* s) {
		if (enabled()) {
			auto it = std::find(s->m_rootMoves.begin(),
				s->m_rootMoves.end(),
				(!m_best.IsNone() ? m_best : pickMove(s)));
			if (s->m_rootMoves.begin() != it)
				SYNCCOUT << "info string swap multipv 1, " << it - s->m_rootMoves.begin() + 1 << SYNCENDL;
			std::swap(s->m_rootMoves[0], *it);
		}
	}
Example #2
0
 void multiPlayer() {
        int myMove;
        int oppMove = 0;
	int connect = 0;
	
	// Find other players
	while(!connect) {
		connect = findPlayer();
	}
	
	// NOTE: Need to build something to determine who goes first
	// Compare Xbee ID's perhaps?
	
	// Begin game
	while(!game.gameOver && connect) {
		if(game.turn) {
			// Pick Move
			myMove = pickMove();
			// Send Move
				sendMove(myMove);
			// Receive new score after opponent takes damage
				game.oppScore = recieveScore();
		} else {				
			// Receive player move and take damage
			game.myScore = attack(recieveMove(), game.myScore);
			// Send new score
			sendScore(game.myScore);
		}		
		// Check game status
		game.gameOver = gameStatus();
		!game.turn;
	}
	if (!connect) {
		printBSOD();
	} else {
		printResults();
	}
}
Example #3
0
void singlePlayer(gameData game) {
	// Setup new game
	setup();
	game.turn = rand() % 2;
	
	// Begin game with computer
	while(!game.gameOver) {
		// Situation depends on game.turn
		if(game.turn) {
			game.myMove = pickMove(globalData);
			game.oppScore = attack(game.myMove, game.oppScore);
		} else {
			// Computer randomly picks an attack with damage b/w 0 and 50
			game.oppMove = rand() % 50 + 1;
			game.myScore = attack(game.oppMove, game.myScore);
		}
		// Check game status
		game.gameOver = gameStatus();
		!game.turn;
	}
	// Display results once there is a lost
	printResults();
}
Example #4
0
void singlePlayer(GlobalState* globalData) {
    static int tempScore = 0;
    static int transition = 0;
    static int movedone = 0;
    // First time playing?
    // Read first time from SRAM
    if (globalData->firstTime == TRUE) {
        if (globalData->newKeyboard) {
            printKeyboard(globalData, "NAME?", 5);
        } else {
            processKeyboard(globalData, game.name, 5);
        }
    }
    if (globalData->doneKeyboard) {
        globalData->firstTime = FALSE;


        if (globalData->newGame) {
            globalData->newGame = 0;
            // Setup new game
            setupGame();
            tempScore = 0;
            transition = 0;
            game.turn = rand() % 2;
            printGame(globalData);
            getCards(); // Assume cards already read by interrupts on switches (?)
        }


        // Wait till someone presses D to continue
        if (globalData->keyPress == 0x0D) {
            transition = 1;
        }

        // Begin game with computer
        if (transition) {
            if (!game.gameOver) {
                // Situation depends on game.turn
                if (game.turn) {
                    if (game.moveSel == 0) {
                        pickMove(globalData);
                    }
                    if (game.moveSel == 1) {

                        tempScore = game.oppScore;
                        game.oppScore = attack(game.myMove, game.myMonster, game.oppScore);
                        if (game.oppScore == tempScore) {
                            prints(0, 10, RED, BLACK, "                    ", 1);
                            prints(0, 18, RED, BLACK, "                    ", 1);
                            prints(0, 26, RED, BLACK, "                    ", 1);
                            prints(0, 10, RED, BLACK, "Missed!", 1);
                        } else {
                            prints(0, 10, RED, BLACK, "                    ", 1);
                            prints(0, 18, RED, BLACK, "                    ", 1);
                            prints(0, 26, RED, BLACK, "                    ", 1);
                            prints(0, 10, RED, BLACK, "Your", 1);
                            printrs(30, 10, RED, BLACK, game.myMonster->monsterName, 1);
                            prints(84, 10, RED, BLACK, "used", 1);
                            printrs(0, 18, RED, BLACK, game.myMove->moveName, 1);
                            prints(0, 26, RED, BLACK, "-    ", 1);
                            integerprint(6, 26, RED, BLACK, tempScore - game.oppScore, 1);
                        }
                        game.moveSel = 0;
                        movedone = 1;
                    }
                } else {
                    // Computer randomly picks a monster and attack
                    game.oppMonster = &myMonsterList[rand() % 3 ];
                    game.oppMove = &game.oppMonster->movelist[rand() % 3];
                    tempScore = game.myScore;
                    game.myScore = attack(game.oppMove, game.oppMonster, game.myScore);
                    if (game.myScore == tempScore) {
                        prints(0, 10, RED, BLACK, "                    ", 1);
                        prints(0, 18, RED, BLACK, "                    ", 1);
                        prints(0, 26, RED, BLACK, "                    ", 1);
                        prints(0, 10, RED, BLACK, "Enmy Missed!", 1);
                    } else {
                        prints(0, 10, RED, BLACK, "                    ", 1);
                        prints(0, 18, RED, BLACK, "                    ", 1);
                        prints(0, 26, RED, BLACK, "                    ", 1);
                        prints(0, 10, RED, BLACK, "Enmy", 1);
                        printrs(30, 10, RED, BLACK, game.oppMonster->monsterName, 1);
                        prints(84, 10, RED, BLACK, "used", 1);
                        printrs(0, 18, RED, BLACK, game.oppMove->moveName, 1);
                        prints(0, 26, RED, BLACK, "-    ", 1);
                        integerprint(6, 26, RED, BLACK, tempScore - game.myScore, 1);
                    }
                    movedone = 1;
                }

                if (movedone == 1) {
                    prints(0, 40, YELLOW, BLACK, "Your Score: ", 1);
                    prints(0, 55, YELLOW, BLACK, "     ", 1);
                    integerprint(0, 55, YELLOW, BLACK, game.myScore, 1);
                    prints(0, 70, WHITE, BLACK, "Opponent Score: ", 1);
                    prints(0, 85, WHITE, BLACK, "     ", 1);
                    integerprint(0, 85, WHITE, BLACK, game.oppScore, 1);
                    // Check game status
                    game.gameOver = gameStatus();
                    game.turn = !game.turn;
                    transition = 0;
                    movedone = 0;
                }
                //                if (game.gameOver == 1) {
                //                    if (globalData->newGame == 0) {
                //                        printResults();
                //                    }
                //                }
            } else {
                if (globalData->newGame == 0) {
                    printResults();
                }
            }
        }
        // Display results once there is a lost
    }
}
Example #5
0
int main ( int argc, char** argv )
{
	srand(time(NULL));
	board_t board[3][3];
	int i, j, k;
	for ( i = 0; i < 3; ++i ) {
		for ( j = 0; j < 3; ++j ) {
			board[i][j] = EMPTY;
		}
	}

	for ( i = 0; i < 2; ++i ) {
		if ( i == 1 ) {
			move_t m = pickMove( board, 0, 0);
			
			assert( m.x >=0 && m.x <= 3 );
			assert( m.y >=0 && m.y <= 3 );
			assert( EMPTY == board[m.x][m.y] );
			board[m.x][m.y] = AI;
		}
		while ( true ) {
			// Show the user the current board
			printBoardUser( board );

			// Get user input, account for incorrect inputs
			uint8_t g = 9;
			while ( g > 8 ) {
				g = getUserInput();
				if ( g > 8 || board[g/3][g%3] != EMPTY)
					printf("Please select a valid move.\n");
			}
			board[g/3][g%3] = USER;

			if ( LOSS == boardStatus( board ) ) {
				printf("Congratulations! You win!\n");
				break;
			}
			else if ( TIE == boardStatus( board ) ) {
				printf("Cat game fool!\n");
				break;
			}

			// AI needs to make a move now
			move_t m = pickMove( board, 0, 0);
			
			assert( m.x >=0 && m.x <= 3 );
			assert( m.y >=0 && m.y <= 3 );
			assert( EMPTY == board[m.x][m.y] );
			board[m.x][m.y] = AI;

			status_t s = boardStatus( board );
			if ( WIN == s ) {
				printf("Haha! You lost!\n");
				break;
			}
			else if ( LOSS == s )
				assert(false);
			else if ( TIE == s ) {
				printf("Cat game fool!\n");
				break;
			}
		}
		for ( k = 0; k < 3; ++k ) {
			for ( j = 0; j < 3; ++j ) {
				board[k][j] = EMPTY;
			}
		}
	}

	return 0;
}