/// <summary>
    /// Initializes a new instance of the <see cref="BGMoveOptions"/> class.
    /// </summary>
    /// <param name="player"></param>
    /// <param name="boardMap"></param>
    /// <param name="diceRoll"></param>
    public BGMoveOptions(BGPlayerID player, BGBoardMap boardMap, BGDiceRoll diceRoll)
    {
        Moves = null;
        Moves = GetMoves(player, boardMap, diceRoll);

        // A player must use both numbers of a roll if possible.
        // If either number can be played but not both, the player must play the larger one.

        if (diceRoll.Roll1 != diceRoll.Roll2 &&
            diceRoll.CanUse(diceRoll.Roll1) &&
            diceRoll.CanUse(diceRoll.Roll2))
        {
            List <BGMove> roll1OnlyMoves = new List <BGMove>();
            List <BGMove> roll2OnlyMoves = new List <BGMove>();
            List <BGMove> bothRollMoves  = new List <BGMove>();

            foreach (BGMove move in Moves)
            {
                BGBoardMap newBoardMap = boardMap.Copy();
                newBoardMap.Use(move);

                BGDiceRoll newDiceRoll = diceRoll.Copy();
                newDiceRoll.Use(move);

                BGMoveOptions newMoveOptions = new BGMoveOptions(player, newBoardMap, newDiceRoll);

                if (move.DiceRoll == diceRoll.Roll1 && newMoveOptions.CanMoveWith(diceRoll.Roll2) ||
                    move.DiceRoll == diceRoll.Roll2 && newMoveOptions.CanMoveWith(diceRoll.Roll1))
                {
                    bothRollMoves.Add(move);
                }
                else if (move.DiceRoll == diceRoll.Roll1 && !newMoveOptions.CanMoveWith(diceRoll.Roll2))
                {
                    roll1OnlyMoves.Add(move);
                }
                else if (move.DiceRoll == diceRoll.Roll2 && !newMoveOptions.CanMoveWith(diceRoll.Roll1))
                {
                    roll2OnlyMoves.Add(move);
                }
            }

            if (bothRollMoves.Count > 0)
            {
                Moves = bothRollMoves;
            }
            else if (diceRoll.Roll1 > diceRoll.Roll2 && roll1OnlyMoves.Count > 0)
            {
                Moves = roll1OnlyMoves;
            }
            else if (diceRoll.Roll2 > diceRoll.Roll1 && roll2OnlyMoves.Count > 0)
            {
                Moves = roll2OnlyMoves;
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Initializes a new instance of the <see cref="BGState"/> class.
    /// </summary>
    /// <param name="boardMap">Board map.</param>
    /// <param name="moveOptions">Move options.</param>
    /// <param name="diceRoll">Dice roll.</param>
    public BGState(BGBoardMap boardMap, BGMoveOptions moveOptions, BGDiceRoll diceRoll)
    {
        BoardMap   = boardMap;
        Moves      = new List <BGMove>();
        NextStates = new Dictionary <BGMove, BGState>();

        foreach (BGMove move in moveOptions.Moves)
        {
            BGBoardMap newBoardMap = boardMap.Copy();
            newBoardMap.Use(move);

            BGDiceRoll newDiceRoll = diceRoll.Copy();
            newDiceRoll.Use(move);

            BGMoveOptions newMoveOptions = new BGMoveOptions(BGPlayerID.Player2, newBoardMap, newDiceRoll);

            Moves.Add(move);
            NextStates[move] = new BGState(newBoardMap, newMoveOptions, newDiceRoll);
        }
    }