コード例 #1
0
    private float GetProbability(int playerNum, MoveMgr.Move move, List <MoveMgr.Move> availableMoves, Grid2D grid)
    {
        // TODO design a "Grid2D" class that allows board to be manipulated without side effects (notifing others and yada)
        if (grid.DoesMoveWin(move))
        {
            return(Win);
        }
        if (availableMoves.Count == 0)
        {
            return(Draw);
        }

        // Apply move to local grid copy.  New grid class should have grid.Add(move) and grid.Remove(move)
        grid.AddMove(move);

        // TODO: apply opponent moves from available moves
        // Recurse GetProbabablity() for each opponent move

        float probablity = 0f;

        for (int i = 0; i < availableMoves.Count - 1; i++)
        {
            List <MoveMgr.Move> nextMoves = availableMoves.GetRange(0, availableMoves.Count);
            nextMoves.Remove(move);
            // probablity += GetOpponetProbability(opponentNum, availableMoves[i], nextMoves, grid);
        }
        return(probablity / (float)(availableMoves.Count - 1));
    }
コード例 #2
0
    /// <summary>
    /// Records a move if valid.
    /// </summary>
    /// <param name="move">1-NumPlayers</param>
    /// <remarks>Use CanMove to determine if MakeMove will record the move</remarks>
    public override void MakeMove(MoveMgr.Move move)
    {
        if (!CanMove(move))
        {
            Debug.LogWarning("Invalid move, not recording move.");
            return;
        }
        _LiveGrid.AddMove(move);

        base.MakeMove(move);
    }