public GameController(bool isFirstAi, bool isSecondAi) { FirstPlayer = new BlackPlayer(CheckerColor.Black, 5, 24, 0, isFirstAi); SecondPlayer = new GreenPlayer(CheckerColor.Green, 18, -1, 23, isSecondAi); GameBoard = new Board(); GameDice = new Dices(); }
public Move GetAMove(Dices dices) { Dice chosenDice; int srcPoint; int diceValue; if (EatenPawns.Count != 0) { PlugableHumanPlayer.InformPawnOnTheBar(); } PlugableHumanPlayer.InformChooseADice(); int.TryParse(PlugableHumanPlayer.GetStrInput(), out diceValue); while ((diceValue != dices.FirstDice.Value && diceValue != dices.SecondDice.Value) || (diceValue == dices.FirstDice.Value && dices.FirstDice.IsUsed && !dices.IsDouble) || (diceValue == dices.SecondDice.Value && dices.SecondDice.IsUsed && !dices.IsDouble)) { PlugableHumanPlayer.InformIncorrectDice(); int.TryParse(PlugableHumanPlayer.GetStrInput(), out diceValue); } if (diceValue == dices.FirstDice.Value) { chosenDice = dices.FirstDice; } else { chosenDice = dices.SecondDice; } if (EatenPawns.Count == 0) { PlugableHumanPlayer.InformChooseAPoint(); bool parseSucceed = int.TryParse(PlugableHumanPlayer.GetStrInput(), out srcPoint); while ((!parseSucceed) || (srcPoint < 1 || srcPoint > 24)) { PlugableHumanPlayer.InformIncorrectPoint(); parseSucceed = int.TryParse(PlugableHumanPlayer.GetStrInput(), out srcPoint); } return(new Move(srcPoint, chosenDice)); } else { if (Type == ePlayer.playerA) { return(new Move(0, chosenDice)); } else { return(new Move(25, chosenDice)); } } }
public bool ValidateTurn(Dices currDice, Board currBoard, int sourceIndex, int targetIndex) { if (currBoard.GetBar(Color).Checkers > 0) { return(GetAvailableBarMoves(currDice, currBoard).ToList().Contains(new KeyValuePair <int, int>(sourceIndex, targetIndex))); } else if (CheckBearOffStage(currBoard)) { return(GetAvailableBearOffMoves(currDice, currBoard).ToList().Contains(new KeyValuePair <int, int>(sourceIndex, targetIndex)));; } else { return(GetAvailableMoves(currDice, currBoard).ToList().Contains(new KeyValuePair <int, int>(sourceIndex, targetIndex)));; } }
public bool Checklegality(Dices currDice, Board currBoard) { if (currBoard.GetBar(Color).Checkers > 0) { return(GetAvailableBarMoves(currDice, currBoard).ToList().Count > 0); } else if (CheckBearOffStage(currBoard)) { return(GetAvailableBearOffMoves(currDice, currBoard).ToList().Count > 0); } else { return(GetAvailableMoves(currDice, currBoard).ToList().Count > 0); } }
public override IEnumerable <KeyValuePair <int, int> > GetAvailableBarMoves(Dices currDice, Board currBoard) { List <KeyValuePair <int, int> > currMoves = new List <KeyValuePair <int, int> >(); if (!currDice.FirstDiceWasPlayed && currBoard[StartPos + currDice.FirstDice].IsAvailable(Color)) { currMoves.Add(new KeyValuePair <int, int>(currBoard.BarSource, StartPos + currDice.FirstDice)); } if (!currDice.IsDouble && !currDice.SecondDiceWasPlayed && currBoard[StartPos + currDice.SecondDice].IsAvailable(Color)) { currMoves.Add(new KeyValuePair <int, int>(currBoard.BarSource, StartPos + currDice.SecondDice)); } return(currMoves); }
public KeyValuePair <int, int> PlayAiTurn(Dices currDice, Board currBoard) { KeyValuePair <int, int> firstMove; if (currBoard.GetBar(Color).Checkers > 0) { firstMove = GetAvailableBarMoves(currDice, currBoard).ToList().First(); MakeBarMove(firstMove.Value, currBoard); } else if (CheckBearOffStage(currBoard)) { firstMove = GetAvailableBearOffMoves(currDice, currBoard).ToList().First(); MakeBearOffMove(firstMove.Key, firstMove.Value, currBoard); } else { firstMove = GetAvailableMoves(currDice, currBoard).ToList().First(); MakeMove(firstMove.Key, firstMove.Value, currBoard); } return(firstMove); }
public override IEnumerable <KeyValuePair <int, int> > GetAvailableMoves(Dices currDice, Board currBoard) { List <KeyValuePair <int, int> > currMoves = new List <KeyValuePair <int, int> >(); for (int i = StartPos + 1; i <= Endpos; i++) { if (!currDice.FirstDiceWasPlayed && i + currDice.FirstDice <= Endpos && currBoard[i + currDice.FirstDice].IsAvailable(Color) && currBoard[i].Color == Color) { currMoves.Add(new KeyValuePair <int, int>(i, i + currDice.FirstDice)); } if (!currDice.IsDouble && !currDice.SecondDiceWasPlayed && i + currDice.SecondDice <= Endpos && currBoard[i + currDice.SecondDice].IsAvailable(Color) && currBoard[i].Color == Color) { currMoves.Add(new KeyValuePair <int, int>(i, i + currDice.SecondDice)); } } return(currMoves); }
public abstract IEnumerable <KeyValuePair <int, int> > GetAvailableBearOffMoves(Dices currDice, Board currBoard);
public BackgammonModel() { Board = new GameBoard(); Dices = new Dices(); IsGameOver = false; }
public override IEnumerable <KeyValuePair <int, int> > GetAvailableBearOffMoves(Dices currDice, Board currBoard) { List <KeyValuePair <int, int> > currMoves = new List <KeyValuePair <int, int> >(); for (int i = HomePos; i >= Endpos; i--) { if (!currDice.FirstDiceWasPlayed && currBoard[i].Color == Color) { if (i - currDice.FirstDice >= Endpos) { if (currBoard[i - currDice.FirstDice].IsAvailable(Color)) { currMoves.Add(new KeyValuePair <int, int>(i, i - currDice.FirstDice)); } } else { currMoves.Add(new KeyValuePair <int, int>(i, i - currDice.FirstDice)); } } if (!currDice.IsDouble && !currDice.SecondDiceWasPlayed && currBoard[i].Color == Color) { if (i - currDice.SecondDice >= Endpos) { if (currBoard[i - currDice.SecondDice].IsAvailable(Color)) { currMoves.Add(new KeyValuePair <int, int>(i, i - currDice.SecondDice)); } } else { currMoves.Add(new KeyValuePair <int, int>(i, i - currDice.SecondDice)); } } } return(currMoves); }