Esempio n. 1
0
    private void UpdateEnemyInfo(BoardChange boardChange)
    {
        if (!boardChange.WasThereAnAttack())
        {
            return;
        }

        PieceInfo         thisPiece      = boardChange.GetPieceFromAction(side);
        PieceInfo         otherPiece     = boardChange.GetPieceFromAction(side.Flip());
        RankPossibilities otherPieceRank = enemyPieces[otherPiece.ID];

        if (boardChange.GetWinningPiece() == null)
        {
            otherPieceRank.TiedBattle(thisPiece.Rank);
        }
        else if (otherPiece == boardChange.GetWinningPiece())
        {
            otherPieceRank.WonBattle(thisPiece.Rank);
        }
        else // This piece is the winner
        {
            otherPieceRank.LostBattle(thisPiece.Rank);
        }

        // Remove from piece pool once piece has been discovered
        PieceRank guaranteedRank = otherPieceRank.GuaranteedRank;

        if (guaranteedRank == PieceRank.Invalid)
        {
            return;
        }

        // DEBUG
        piecePool[(int)guaranteedRank]--;
        pieceCounterPanel.UpdateText(piecePool);

        // If piece pool reaches 0, all other pieces can't be this piece
        if (piecePool[(int)guaranteedRank] > 0)
        {
            return;
        }

        foreach (RankPossibilities rankPossibilities in enemyPieces.Values)
        {
            if (rankPossibilities.GuaranteedRank == guaranteedRank)
            {
                continue;
            }

            rankPossibilities.RemovePiecePossibility(guaranteedRank);
        }
    }
Esempio n. 2
0
    public override void Initialize(
        GameManager gameManager,
        Board board,
        PieceContainer myPieces,
        PieceContainer otherPieces)
    {
        base.Initialize(gameManager, board, myPieces, otherPieces);

        foreach (PieceInfo pieceInfo in otherPieces)
        {
            RankPossibilities rankPossibilities = new RankPossibilities();
            enemyPieces.Add(pieceInfo.ID, rankPossibilities);
        }

        pieceCounterPanel.UpdateText(piecePool);

        TogglePieceVisibility();
    }
Esempio n. 3
0
    private float EvaluateMove(Board boardCopy, MoveInfo move, int depth)
    {
        float resultSum = 0f;

        if (side == Side.A)
        {
            if (move.GetDifference().y > 0)
            {
                resultSum += forwardBonus;
            }
        }
        else
        {
            if (move.GetDifference().y < 0)
            {
                resultSum += forwardBonus;
            }
        }

        // If piece exists in next position, this is an attacking move
        if (boardCopy.DoesPieceExistInPosition(move.NewPosition))
        {
            // Get needed vars
            PieceInfo         oldPosPiece            = boardCopy.GetPieceFromPosition(move.OldPosition);
            PieceInfo         newPosPiece            = boardCopy.GetPieceFromPosition(move.NewPosition);
            PieceInfo         myPiece                = boardCopy.CurrentSide == side ? oldPosPiece : newPosPiece;
            PieceInfo         otherPiece             = boardCopy.CurrentSide == side ? newPosPiece : oldPosPiece;
            PieceRank         myRank                 = myPiece.Rank;
            RankPossibilities otherRankPossibilities = enemyPieces[otherPiece.ID];

            // Get win chance
            float winChance = CalculateWinChance(otherRankPossibilities, myRank);
            if (boardCopy.CurrentSide != side)
            {
                winChance = 1f - winChance;
            }

            if (winChance >= 0.99f) // Guaranteed to win!
            {
                resultSum += SimulateWin(boardCopy, move, depth);
            }
            else if (winChance <= 0.01f) // Guaranteed to lose!
            {
                // Optimization: don't explore moves where guaranteed to lose!
                return(-losingBattlePenalty * 10f);
            }
            else // Simulate both outcomes and multiply each with it's chance
            {
                // Simulated win
                resultSum += SimulateWin(boardCopy, move, depth) * winChance;

                // Simulated loss
                float lossChance = 1f - winChance;
                resultSum += SimulateLoss(boardCopy, move, depth) * lossChance;
            }
        }
        else
        {
            float myResult = SimulateNormal(boardCopy, move, depth);
            resultSum += myResult;
        }

        return(resultSum);
    }