Esempio n. 1
0
        private static Board _With(LogicalPiece played, LogicalPiece bound, Board board)
        {
            // this looks like shit I'm sorry: This advances from one step in the direction of to
            int Step(int from, int to) => from + (from < to ? 1 : to == from ? 0 : -1);
            Func <PlayerColor, LogicalPiece> StepTowards(LogicalPiece origin, LogicalPiece destination) =>
            playerColor => new LogicalPiece(Step(origin.X, destination.X), Step(origin.Z, destination.Z), playerColor);

            LogicalPiece next         = played;
            var          currentBoard = board;

            while (!next.Equals(bound))
            {
                var advanceOneStepToBoundIn = StepTowards(next, bound);

                LogicalPiece toRemove = advanceOneStepToBoundIn(played.Color.Opposing());
                LogicalPiece toAdd    = advanceOneStepToBoundIn(played.Color);

                currentBoard = currentBoard
                               .Without(toRemove)
                               .With(toAdd);

                next = toAdd;
            }

            return(currentBoard);
        }
Esempio n. 2
0
        private static IReadOnlyList <Piece> AddToGameObjectState(LogicalPiece piece, IReadOnlyList <Piece> gameObjectState)
        {
            List <Piece> intermediatePhysicalState = new List <Piece>(gameObjectState);

            intermediatePhysicalState.Add(InstantiateAsPiece(piece));

            return(intermediatePhysicalState.AsReadOnly());
        }
Esempio n. 3
0
        private static IReadOnlyList <LogicalPiece> RemoveFromLogicalState(LogicalPiece piece, IReadOnlyList <LogicalPiece> state)
        {
            List <LogicalPiece> intermediateLogicalState = new List <LogicalPiece>(state);

            intermediateLogicalState.Remove(piece);

            return(intermediateLogicalState.AsReadOnly());
        }
Esempio n. 4
0
        private static IReadOnlyList <LogicalPiece> AddToLogicalState(LogicalPiece piece, IReadOnlyList <LogicalPiece> state)
        {
            List <LogicalPiece> intermediateLogicalState = new List <LogicalPiece>(state);

            intermediateLogicalState.Add(piece);

            return(intermediateLogicalState.AsReadOnly());
        }
Esempio n. 5
0
        private static IReadOnlyList <Piece> RemoveFromGameObjectState(LogicalPiece piece, IReadOnlyList <Piece> gameObjectState)
        {
            Piece toRemove = gameObjectState.First(physical => physical.ToLogicalPiece().Equals(piece));

            Object.Destroy(toRemove.gameObject);

            List <Piece> intermediatePhysicalState = new List <Piece>(gameObjectState);

            intermediatePhysicalState.RemoveAll(physical => physical.ToLogicalPiece().Equals(piece));

            return(intermediatePhysicalState.AsReadOnly());
        }
Esempio n. 6
0
        private Board _Without(LogicalPiece piece, Board board)
        {
            if (!board.LogicalState.Contains(piece))
            {
                return(board);
            }

            var logicalState = RemoveFromLogicalState(piece, board.LogicalState);

            return(_isReal ?
                   new Board(logicalState, RemoveFromGameObjectState(piece, board._physicalState)) :
                   new Board(logicalState));
        }
Esempio n. 7
0
        private Board _With(LogicalPiece piece, Board board)
        {
            if (board.LogicalState.Contains(piece))
            {
                return(board);
            }

            var logicalState = AddToLogicalState(piece, board.LogicalState);

            return(_isReal ?
                   new Board(logicalState, AddToGameObjectState(piece, board._physicalState)) :
                   new Board(logicalState));
        }
Esempio n. 8
0
 private static Piece InstantiateAsPiece(LogicalPiece piece)
 {
     // this has the very intended sideeffect of actually creating the Piece in the GameWorld.
     // Should be I/O but it isn't
     return(Object
            .Instantiate(
                Game.Instance.GetPrefForColor(piece.Color),
                new Vector3(piece.X, 0f, piece.Z),
                Quaternion.identity
                )
            .AddComponent <Piece>()
            .Init(piece));
 }
Esempio n. 9
0
 public Board Without(LogicalPiece piece) => _Without(piece, this);
Esempio n. 10
0
 public Piece Init(LogicalPiece piece)
 {
     _underlying = piece;
     return(this);
 }