public bool MakeBarMove(int target, Board currBoard) { if (!currBoard[target].IsAvailable(Color)) { return(false); } if (currBoard[target].Color == CheckerColor.Empty) { currBoard.GetBar(Color).RemoveBarChecker(); currBoard[target].AddChecker(Color); } else if (currBoard[target].Color == Color) { currBoard.GetBar(Color).RemoveBarChecker(); currBoard[target].AddChecker(); } else { currBoard.GetBar(Color).RemoveBarChecker(); currBoard.GetOtherBar(Color).AddBarChecker(); currBoard[target].RemoveChecker(); currBoard[target].AddChecker(Color); } return(true); }
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 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); }