Exemplo n.º 1
0
        public static void ExecuteMoves(Game game, bool flipPieceState = false)
        {
            if (game.ActiveMoves.Count() == 0)
            {
                return;
            }

            Func<BoardSpaceState, BoardSpaceState> getPieceForPlayer = boardSpaceState => flipPieceState ? boardSpaceState.TogglePlayer() : boardSpaceState;

            if (!(game.ActiveMoves.Count() == 2 && GameUtils.AreNeighbors(game.ActiveMoves.First(), game.ActiveMoves.Last())))
            {
                // TODO the recepient can't capture anything - perhaps a board flipping issue?
                var opponentsLoc =
                    game.ActiveMoves
                        .Pairwise()
                        .Select((moves) => GameUtils.SpaceBetween(moves.Item1, moves.Item2))
                        .Where(loc => GameUtils.IsOpponent(getPieceForPlayer(game.GetPieceAt(loc))));

                // TODO this doesn't actually fire
                Debug.Assert(opponentsLoc.Count() > 0, "If we're doing a jump, we should find some pieces to capture.");

                foreach (var opponentLoc in opponentsLoc)
                {
                    game.CapturePiece(game.GetPieceAt(opponentLoc));
                    game.SetPieceLocation(opponentLoc, BoardSpaceState.None);
                }
            }

            GameUtils.MovePiece(game, game.ActiveMoves.First(), game.ActiveMoves.Last());

            game.ClearActiveMoves();

            game.Winner = GameValidator.GameWinner(game);

            game.WaitingOn = game.WaitingOn.Toggle();
        }