Пример #1
0
        public bool doTheTurn(OneStep thisTurn)
        {
            var currentPlayer = (color.currentColor == Color.color.white) ? player1 : player2;
            var Opponent      = (currentPlayer == player1) ? player2 : player1;

            Possabilitiesleft = Turn.excecuteTheTurn(thisTurn, Possabilitiesleft, color, currentPlayer, Opponent, board);
            if (Possabilitiesleft.Count == 0)
            {
                return(false);
            }
            return(true);
        }
Пример #2
0
 internal static List <OneStep> excecuteTheTurn(OneStep thisTurn, List <OneStep> possabilitiesleft, Color color, Player currentPlayer, Player opponent, Board board)
 {
     if (thisTurn._from > 23)
     {
         return(new ExecuteJailTurn().excuteTurn(thisTurn, possabilitiesleft, color, currentPlayer, opponent, board));
     }
     if (currentPlayer.isInTheLastZone == true)
     {
         return(new ExecuteLastZoneTurn().excuteTurn(thisTurn, possabilitiesleft, color, currentPlayer, opponent, board));
     }
     return(new regularExecuteTurn().excuteTurn(thisTurn, possabilitiesleft, color, currentPlayer, opponent, board));
 }
Пример #3
0
 internal void StepInATurn(OneStep ChoseOfUser, Player opponent, Player currentPlayer)
 {
     if (ChoseOfUser._from > 23)
     {
         Jail.putTheTiles(ChoseOfUser._to, currentPlayer, this);
         return;
     }
     if (ChoseOfUser._to > 23)
     {
         LastZone.putTheTiles(ChoseOfUser._from, currentPlayer, this);
         return;
     }
     RegularZone.putTheTiles(ChoseOfUser, currentPlayer, opponent, this);
 }
Пример #4
0
        public List <OneStep> excuteTurn(OneStep thisTurn, List <OneStep> Possabilitiesleft, Color color, Player currentPlayer, Player opponent, Board board)
        {
            int  startPoint = (currentPlayer.color == Color.color.white) ? (thisTurn._from + 1) : (24 - thisTurn._from);
            int  i;
            bool isRemoved = false;
            var  colorGoTo = (color.currentColor == Color.color.black) ? 1 : -1;

            for (i = 0; i < Turn.currentRoll.Count && thisTurn._to != 26; i++)
            {
                if (Turn.currentRoll[i] == (thisTurn._to - thisTurn._from) * colorGoTo)
                {
                    Turn.currentRoll.RemoveAt(i);
                    isRemoved = true;
                    break;
                }
            }

            if (Turn.currentRoll.Count > 0 && isRemoved == false)
            {
                if (Turn.currentRoll[0] >= startPoint)
                {
                    Turn.currentRoll.RemoveAt(0);
                }
                else
                {
                    for (i = 1; i < Turn.currentRoll.Count; i++)
                    {
                        if (Turn.currentRoll[i] >= startPoint)
                        {
                            Turn.currentRoll.RemoveAt(i);
                            break;
                        }
                    }
                }
            }

            board.StepInATurn(thisTurn, opponent, currentPlayer);
            if (Turn.currentRoll.Count == 0)
            {
                return(new List <OneStep>());
            }
            Possabilitiesleft = returnPossabilities(board, color.currentColor, currentPlayer);
            return(Possabilitiesleft);
        }
Пример #5
0
 public List <OneStep> excuteTurn(OneStep thisTurn, List <OneStep> Possabilitiesleft, Color color, Player currentPlayer, Player opponent, Board board)
 {
     board.StepInATurn(thisTurn, opponent, currentPlayer);
     for (int i = 0; i < Turn.currentRoll.Count; i++)
     {
         if (thisTurn._to < 6)
         {
             if (Turn.currentRoll[i] == thisTurn._to + 1)
             {
                 Turn.currentRoll.RemoveAt(i);
                 break;
             }
         }
         if (Turn.currentRoll[i] == 24 - thisTurn._to)
         {
             Turn.currentRoll.RemoveAt(i);
             break;
         }
     }
     return(returnPossabilities(board, color.currentColor, currentPlayer));
 }
Пример #6
0
        internal static void putTheTiles(OneStep chose, Player currentPlayer, Player Opponent, Board board)
        {
            if (currentPlayer.color == Color.returnOpposite(board.SpotsOnBoard[chose._to].color))
            {
                board.addJailNumber(currentPlayer.color);
                Opponent.isInTheLastZone = false;
            }

            if (board.SpotsOnBoard[chose._to].color != board.SpotsOnBoard[chose._from].color)
            {
                board.SpotsOnBoard[chose._to].color         = currentPlayer.color;
                board.SpotsOnBoard[chose._to].numberOfTiles = 1;
            }
            else
            {
                board.SpotsOnBoard[chose._to].numberOfTiles++;
            }

            if (--(board.SpotsOnBoard[chose._from].numberOfTiles) == 0)
            {
                board.SpotsOnBoard[chose._from].color = Color.color.empty;
            }
        }
Пример #7
0
        public List <OneStep> excuteTurn(OneStep thisTurn, List <OneStep> Possabilitiesleft, Color color, Player currentPlayer, Player opponent, Board board)
        {
            int i;
            int colorGoTo = (color.currentColor == Color.color.black) ? 1 : -1;
            Action <OneStep, List <OneStep> > removeFromPossabilities = (x, y) => { };

            for (i = 0; i < Turn.currentRoll.Count && thisTurn._to != 26; i++)
            {
                if (Turn.currentRoll[i] == (thisTurn._to - thisTurn._from) * colorGoTo)
                {
                    Turn.currentRoll.RemoveAt(i);
                    break;
                }
            }

            if (board.getNumberOfTiles(color.currentColor) == 0)
            {
                foreach (var cube in Turn.currentRoll)
                {
                    if (cube * colorGoTo + thisTurn._to < 24 && cube * colorGoTo + thisTurn._to > 0 && (board.SpotsOnBoard[cube * colorGoTo + thisTurn._to].numberOfTiles < 2 || board.SpotsOnBoard[cube * colorGoTo + thisTurn._to].color == currentPlayer.color))
                    {
                        Possabilitiesleft.Add(new OneStep(thisTurn._to, cube * colorGoTo + thisTurn._to));
                    }
                }
            }

            board.StepInATurn(thisTurn, opponent, currentPlayer);

            if (thisTurn._from < 23)
            {
                if (board.SpotsOnBoard[thisTurn._from].numberOfTiles == 0)
                {
                    removeFromPossabilities += (turn, Possabilitieslist) =>
                    {
                        Possabilitiesleft = (from step in Possabilitiesleft
                                             where (turn._from != step._from)
                                             select step).ToList();
                    };
                }
            }

            if (!Turn.currentRoll.Contains((thisTurn._to - thisTurn._from) * colorGoTo))
            {
                removeFromPossabilities += (turn, Possabilitieslist) =>
                {
                    Possabilitiesleft = (from step in Possabilitiesleft
                                         where (turn._to - turn._from != step._to - step._from)
                                         select step).ToList();
                };
            }

            var finishValue = (colorGoTo < 0) ? 24 : 18;

            for (i = finishValue - 18; i < finishValue; i++)
            {
                if (board.SpotsOnBoard[i].color == color.currentColor)
                {
                    break;
                }
            }

            if (i == finishValue && currentPlayer.isInTheLastZone != true)
            {
                currentPlayer.isInTheLastZone = true;
                if (Turn.currentRoll.Count == 0)
                {
                    return(new List <OneStep>());
                }
                Possabilitiesleft = returnPossabilities(board, color.currentColor, currentPlayer);

                return(Possabilitiesleft);
            }

            removeFromPossabilities.Invoke(thisTurn, Possabilitiesleft);
            return(Possabilitiesleft);
        }