コード例 #1
0
 public void OperateAi(Player currPlayer)
 {
     while (PlayerWon == CheckerColor.Empty &&
            currPlayer.Turns > 0 &&
            currPlayer.Checklegality(GameDice, GameBoard))
     {
         KeyValuePair <int, int> currMove = currPlayer.PlayAiTurn(GameDice, GameBoard);
         currPlayer.Turns--;
         if (!GameDice.IsDouble)
         {
             if (currPlayer.Color == CheckerColor.Black)
             {
                 if (currMove.Key - currMove.Value == GameDice.FirstDice)
                 {
                     GameDice.DisableFirstDice();
                 }
                 else
                 {
                     GameDice.DisableSecondDice();
                 }
             }
             else
             {
                 int gameMove;
                 if (currMove.Key == GameBoard.BarSource)
                 {
                     gameMove = currMove.Value + 1;
                 }
                 else
                 {
                     gameMove = currMove.Value - currMove.Key;
                 }
                 if (gameMove == GameDice.FirstDice)
                 {
                     GameDice.DisableFirstDice();
                 }
                 else
                 {
                     GameDice.DisableSecondDice();
                 }
             }
         }
     }
     if (PlayerWon != currPlayer.Color)
     {
         SwapTurns();
     }
 }
コード例 #2
0
        public bool PlayTurn(int sourceIndex, int targetIndex)
        {
            if (!CurrentPlayer.ValidateTurn(GameDice, GameBoard, sourceIndex, targetIndex))
            {
                return(false);
            }

            if (FirstPlayer.IsPlayerTurn)
            {
                if (FirstPlayer.PlayTurn(sourceIndex, targetIndex, GameBoard))
                {
                    IsTurnStart = false;
                    FirstPlayer.Turns--;
                    if (FirstPlayer.Turns == 0)
                    {
                        SwapTurns();
                    }
                    else if (!GameDice.IsDouble)
                    {
                        if (sourceIndex - targetIndex == GameDice.FirstDice)
                        {
                            GameDice.DisableFirstDice();
                        }
                        else
                        {
                            GameDice.DisableSecondDice();
                        }
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (SecondPlayer.PlayTurn(sourceIndex, targetIndex, GameBoard))
                {
                    IsTurnStart = false;
                    SecondPlayer.Turns--;
                    if (SecondPlayer.Turns == 0)
                    {
                        SwapTurns();
                    }
                    else if (!GameDice.IsDouble)
                    {
                        int gameMove;
                        if (sourceIndex == GameBoard.BarSource)
                        {
                            gameMove = targetIndex + 1;
                        }
                        else
                        {
                            gameMove = targetIndex - sourceIndex;
                        }
                        if (gameMove == GameDice.FirstDice)
                        {
                            GameDice.DisableFirstDice();
                        }
                        else
                        {
                            GameDice.DisableSecondDice();
                        }
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }