コード例 #1
0
    private IEnumerator AiMovesCoroutine()
    {
        yield return(new WaitForSeconds(0.1f));

        Move move = alphaBeta.RunAlphaBeta(game);

        game.MovePawn(move);         // makes move in the model
        PawnData pawn = gameBoard.GetPawnAtCoord(move.startingX, move.startingZ);

        pawn.x = move.finalX;
        pawn.z = move.finalZ;
        pawn.GetComponent <MovePawnAnimation>().moveToDestination = true;        // moves pawn in the view (graphically)
    }
コード例 #2
0
    //fa giocare due ai l'uno contro l'altro per numberOfMatches volte. Se p2 è null, crea un giocatore random.
    public PairOfScores MatchTwoAi(AlphaBeta p1, AlphaBeta p2, int numberOfMatches, int indexOfP1, int indexOfP2)
    {
        int       player1Score     = 0;
        int       player2Score     = 0;
        PawnType  pawnType1        = p1.aiPlayer;
        PawnType  opponentPawnType = pawnType1 == PawnType.Goose ? PawnType.Fox : PawnType.Goose;
        AlphaBeta player2;

        if (p2 == null)
        {
            player2 = new AlphaBeta(opponentPawnType, 5, null, true);
        }
        else
        {
            player2 = p2;
        }
        AlphaBeta goosePlayer = pawnType1 == PawnType.Goose ? p1 : player2;
        AlphaBeta foxPlayer   = goosePlayer == p1 ? player2 : p1;

        for (int i = 0; i < numberOfMatches; i++)
        {
            int  turnLimit   = 100;
            int  turnCounter = 0;
            Game game        = new Game(15, true);

            while (!game.GameOver() && turnCounter < turnLimit)
            {
                Move move1 = goosePlayer.RunAlphaBeta(game);
                game.MovePawn(move1);
                if (game.GameOver())
                {
                    break;
                }
                Move move2 = foxPlayer.RunAlphaBeta(game);
                game.MovePawn(move2);
                turnCounter++;
            }

            if (game.winner == p1.aiPlayer)
            {
                player1Score += 32000;
            }
            else if (game.winner == player2.aiPlayer)
            {
                player2Score += 32000;
            }
            else
            {
                if (p1.aiPlayer == PawnType.Fox)
                {
                    player1Score += 15 - game.GetGooseNumber();
                    player2Score += game.GetGooseNumber();
                }
                else if (p1.aiPlayer == PawnType.Goose)
                {
                    player1Score += game.GetGooseNumber();
                    player2Score += 15 - game.GetGooseNumber();
                }
            }
        }
        return(new PairOfScores(player1Score, player2Score));
    }