Пример #1
0
 public List <int> GetMoveableCheckers(CheckerColor color)
 {
     if (color != turnColor)
     {
         throw new InvalidOperationException("Cant get moveable checkers for player " + color + " when it is " + color.OppositeColor() + "'s turn");
     }
     return(MovesCalculator.GetMoveableCheckers(currentGameBoardState, color, movesLeft).ToList());
 }
Пример #2
0
        public void Move(CheckerColor color, int from, int targetPosition)
        {
            if (GameIsOver())
            {
                Console.WriteLine("Game is over, so doing nothing");
                return;
            }

            if (color != playerToMove())
            {
                throw new InvalidOperationException(color + " can't move when it is " + color.OppositeColor() + "'s turn");
            }

            //TODO REMOVE THIS SHIT
            numberOfMovesMade++;

            MovesCalculator mts = new MovesCalculator(currentGameBoardState, color, from, movesLeft);

            if (!mts.LegalToMoveToPosition(targetPosition))
            {
                throw new InvalidOperationException("Illegal to move " + color + " form " + from + " to " + targetPosition);
            }

            MovesCalculator.MoveState resultingState = mts.MoveToPosition(targetPosition);
            currentGameBoardState = resultingState.state;
            movesLeft             = resultingState.movesLeft;
            Changes.AddRange(resultingState.changes);
            NotifyAllViews();

            foreach (Change change in resultingState.changes)
            {
                if (change is Move)
                {
                    CurrentTurn.moves.Add(change as Move);
                }
            }

            if (GameIsOver())
            {
                //Console.WriteLine("Game is over!! Terminating"); // Michaelius: The view notifies gameover. ML doesn't like printing.
                return;
            }

            if (movesLeft.Count() == 0)
            {
                changeTurns();
            }
            else if (GetMoveableCheckers().Count() == 0)
            {
                changeTurns();
            }
        }
Пример #3
0
        public static IEnumerable <ReachableState> GetReachableStatesThisTurn(GameBoardState state, CheckerColor color, List <int> movesLeft)
        {
            IEnumerable <int> moveableCheckers = GetMoveableCheckers(state, color, movesLeft);
            List <MoveState>  moveStates       = new List <MoveState>();

            foreach (int pos in moveableCheckers)
            {
                var tmp = new MovesCalculator(state, color, pos, movesLeft).reachableStates;
                foreach (var moveState in tmp)
                {
                    if (moveState.IsFinal)
                    {
                        moveStates.Add(moveState);
                    }
                }
            }
            if (moveStates.Count() == 0)
            {
                return(new List <ReachableState>());
            }

            return(moveStates.Select(moveState => new ReachableState(moveState.state, moveState.MovesMade())));
        }
Пример #4
0
        public HashSet <int> GetLegalMovesFor(CheckerColor color, int initialPosition)
        {
            MovesCalculator root = new MovesCalculator(currentGameBoardState, color, initialPosition, GetMovesLeft());

            return(new HashSet <int>(root.GetReachablePositions()));
        }