private void tile_OnTileSelected(object sender, EventArgs e) { if (GameEngine.currentPlayer == Players.Black) { return; } Tile tile = (Tile)sender; if (previousTileSelected) { if (!PieceMover.IsValidMove(this, originalTile, tile.Row, tile.Column)) { previousTileSelected = false; return; } PieceMover.MovePiece(this, originalTile, tile.Row, tile.Column); previousTileSelected = false; PlayerTurnDone?.Invoke(this, null); return; } originalTile = tile; previousTileSelected = true; }
private void Start() { PlayerCount++; pieceMover = GetComponent <PieceMover>(); moveCalculator = GetComponent <MoveCalculator>(); pieceMover.enabled = false; }
public PieceMover Instantiate(PieceMover prefab, EnemyModel enemyModel) { return(Instantiate(prefab, GetSquarePosition(enemyModel.CurrentSquare.Value), enemyModel.CurrentRotation.Value, transform)); }
public void WhenEnPassantMoveIsPassed_Move_ReturnsRemovedPawn() { var movementHistory = new Mock <IMovementHistory>(MockBehavior.Strict); var promoterMock = new Mock <IPiecePromoter>(MockBehavior.Strict); var castlingMoverMock = new Mock <ICastlingMover>(MockBehavior.Strict); var enPassantMoverMock = new Mock <IEnPassantMover>(MockBehavior.Strict); var pawnToRemoveMock = new Mock <IChessPiece>(MockBehavior.Strict); var pieces = new List <IChessPiece>(); var chessMove = new ChessMove(new Position(4, 7), new Position(0, 7)); promoterMock .Setup(p => p.PromoteIfPromotionMove(chessMove, pieces)) .Returns(false); castlingMoverMock .Setup(c => c.PerformCastlingIfCastlingMove(chessMove, pieces)) .Returns(false); enPassantMoverMock .Setup(e => e.PerformEnPassantIfApplicable(chessMove, pieces)) .Returns(pawnToRemoveMock.Object); var pieceMover = new PieceMover(movementHistory.Object, promoterMock.Object, castlingMoverMock.Object, enPassantMoverMock.Object); var result = pieceMover.Move(chessMove, pieces); Assert.AreEqual(pawnToRemoveMock.Object, result); }
private void InitializeBoard() { for (int i = 0; i < 64; i++) { int x = i % 8; int y = i / 8; //Create square GameObject obj = Instantiate(SquareObj, Vector3.zero, Quaternion.identity) as GameObject; obj.transform.SetParent(pieces, true); //set parent obj.transform.localPosition = new Vector3(-244 + 64 * x, 204 - 64 * y, 0); //Position it PieceMover pm = obj.GetComponent <PieceMover>(); //Get piece component pm.index = i; //Set index pm.manager = this; //Set manager reference pm.UpdateBoard = UpdateBoard; if ((i + y) % 2 == 0) //Change sprites according to squares { obj.GetComponent <Image>().sprite = WhitePieces.Square; //White square } else { obj.GetComponent <Image>().sprite = BlackPieces.Square; //Black square } //Save a square in a squares array at right index SquaresObj[i] = obj.transform; } }
public MovePieceCommandHandler(IGamesRepository gamesRepository, IMovesRepository movesRepository, IServiceBus serviceBus) { this.gamesRepository = gamesRepository; this.movesRepository = movesRepository; this.serviceBus = serviceBus; pieceMover = new PieceMover(); }
public void WhenThereIsNoCapture_Move_ReturnsNull_IncrementsMoveCounter_AndAddsMoveToMovmentHistory() { var movementHistory = new Mock <IMovementHistory>(MockBehavior.Strict); var promoterMock = new Mock <IPiecePromoter>(MockBehavior.Strict); var castlingMoverMock = new Mock <ICastlingMover>(MockBehavior.Strict); var enPassantMoverMock = new Mock <IEnPassantMover>(MockBehavior.Strict); var movedPieceMock = new Mock <IChessPiece>(MockBehavior.Strict); var otherPieceMock = new Mock <IChessPiece>(MockBehavior.Strict); var piecePosition = new Position(3, 1); var destination = new Position(3, 3); var chessMove = new ChessMove(piecePosition, destination); movedPieceMock .SetupGet(p => p.Position) .Returns(piecePosition); movedPieceMock .SetupSet(p => p.Position = destination); movedPieceMock .Setup(p => p.IncrementMoveCounter()); otherPieceMock .SetupGet(p => p.Position) .Returns(new Position(1, 1)); var pieces = new List <IChessPiece>() { movedPieceMock.Object, otherPieceMock.Object }; promoterMock .Setup(p => p.PromoteIfPromotionMove(chessMove, pieces)) .Returns(false); castlingMoverMock .Setup(c => c.PerformCastlingIfCastlingMove(chessMove, pieces)) .Returns(false); enPassantMoverMock .Setup(e => e.PerformEnPassantIfApplicable(chessMove, pieces)) .Returns <IChessPiece>(null); movementHistory .Setup(h => h.Add(chessMove)); var pieceMover = new PieceMover(movementHistory.Object, promoterMock.Object, castlingMoverMock.Object, enPassantMoverMock.Object); var result = pieceMover.Move(chessMove, pieces); Assert.AreEqual(null, result); movedPieceMock .VerifySet(p => p.Position = destination); movedPieceMock .Verify(p => p.IncrementMoveCounter()); movementHistory .Verify(h => h.Add(chessMove)); }
public IChessGame Create() { var piecesFactory = new PiecesFactory(); var movementHistory = new MovementHistory(); var piecePromoter = new PiecePromoter(movementHistory); var castlingMover = new CastlingMover(movementHistory); var enPassantMover = new EnPassantMover(movementHistory); var pieceMover = new PieceMover(movementHistory, piecePromoter, castlingMover, enPassantMover); var chessBoard = new ChessBoard(piecesFactory, pieceMover); List <IMovement> movements = new(); var pawnMovement = new PawnMovement(chessBoard); var enPassantMovement = new EnPassantMovement(chessBoard); var kingMovement = new KingMovement(chessBoard); var horizontalMovement = new HorizontalMovement(chessBoard); var verticalMovement = new VerticalMovement(chessBoard); var pdiagonalMovement = new PositiveDiagonalMovement(chessBoard); var ndiagonalMovement = new NegativeDiagonalMovement(chessBoard); var knightMovement = new KnightMovement(chessBoard); movements.Add(pawnMovement); movements.Add(enPassantMovement); movements.Add(kingMovement); movements.Add(horizontalMovement); movements.Add(verticalMovement); movements.Add(pdiagonalMovement); movements.Add(ndiagonalMovement); movements.Add(knightMovement); var movementComposite = new MovementComposite(movements); List <IMovement> movementsWithCastling = new(); var queensideCastlingMovement = new QueensideCastlingMovement(chessBoard, movementComposite); var kingsideCastlingMovement = new KingsideCastlingMovement(chessBoard, movementComposite); movementsWithCastling.Add(movementComposite); movementsWithCastling.Add(queensideCastlingMovement); movementsWithCastling.Add(kingsideCastlingMovement); var movementCompositeWithCastling = new MovementComposite(movementsWithCastling); var promotionDetector = new PromotionDetector(chessBoard); var checkDetector = new CheckDetector(chessBoard, movementCompositeWithCastling); var legalMovement = new LegalMovement(chessBoard, movementCompositeWithCastling, checkDetector); var moveValidator = new MoveValidator(chessBoard, legalMovement, promotionDetector); var gameFinishedDetector = new GameFinishedDetector(checkDetector, legalMovement); return(new ChessGame(chessBoard, moveValidator, promotionDetector, gameFinishedDetector, legalMovement)); }
public void WhenThereWasCapture_ReverseLastMove_ReturnsTrue_DecrementsMoveCounter_AndRemovesMoveFromMovmentHistory() { var movementHistory = new Mock <IMovementHistory>(MockBehavior.Strict); var promoterMock = new Mock <IPiecePromoter>(MockBehavior.Strict); var castlingMoverMock = new Mock <ICastlingMover>(MockBehavior.Strict); var enPassantMoverMock = new Mock <IEnPassantMover>(MockBehavior.Strict); var movedPieceMock = new Mock <IChessPiece>(MockBehavior.Strict); var otherPieceMock = new Mock <IChessPiece>(MockBehavior.Strict); var capturedPieceMock = new Mock <IChessPiece>(MockBehavior.Strict); var piecePreviousPosition = new Position(3, 1); var pieceCurrentPosition = new Position(3, 3); var lastChessMove = new ChessMove(piecePreviousPosition, pieceCurrentPosition, true); movedPieceMock .SetupGet(p => p.Position) .Returns(pieceCurrentPosition); movedPieceMock .SetupSet(p => p.Position = piecePreviousPosition); movedPieceMock .Setup(p => p.DecrementMoveCounter()); otherPieceMock .SetupGet(p => p.Position) .Returns(new Position(1, 1)); var pieces = new List <IChessPiece>() { movedPieceMock.Object, otherPieceMock.Object }; promoterMock .Setup(p => p.DepromoteIfPromotionMove(lastChessMove, pieces)) .Returns(lastChessMove); castlingMoverMock .Setup(c => c.UndoCastlingIfCastlingMove(lastChessMove, pieces)) .Returns(false); movementHistory .Setup(h => h.RemoveLastMove()) .Returns(lastChessMove); var pieceMover = new PieceMover(movementHistory.Object, promoterMock.Object, castlingMoverMock.Object, enPassantMoverMock.Object); var result = pieceMover.ReverseLastMove(pieces); Assert.AreEqual(true, result); movedPieceMock .VerifySet(p => p.Position = piecePreviousPosition); movedPieceMock .Verify(p => p.DecrementMoveCounter()); movementHistory .Verify(h => h.RemoveLastMove()); }
public void WhenPromotionMoveWasLast_ReverseLastMove_ReversesPawnMove_AndReturnsWhetherItWasCaptureMove() { var movementHistory = new Mock <IMovementHistory>(MockBehavior.Strict); var promoterMock = new Mock <IPiecePromoter>(MockBehavior.Strict); var castlingMoverMock = new Mock <ICastlingMover>(MockBehavior.Strict); var enPassantMoverMock = new Mock <IEnPassantMover>(MockBehavior.Strict); var pawnMock = new Mock <IChessPiece>(MockBehavior.Strict); var pawnPreviousPosition = new Position(3, 6); var pawnCurrentPosition = new Position(3, 7); var promotionMove = new ChessMove(new Position(0, 0), new Position(0, 0), pawnPromotion: ChessPieceType.Knight); var pawnMoveBeforePromotion = new ChessMove(pawnPreviousPosition, pawnCurrentPosition); pawnMock .SetupGet(p => p.Position) .Returns(pawnCurrentPosition); pawnMock .SetupSet(p => p.Position = pawnPreviousPosition); pawnMock .Setup(p => p.DecrementMoveCounter()); var pieces = new List <IChessPiece>() { pawnMock.Object }; promoterMock .Setup(p => p.DepromoteIfPromotionMove(promotionMove, pieces)) .Returns(pawnMoveBeforePromotion); castlingMoverMock .Setup(c => c.UndoCastlingIfCastlingMove(promotionMove, pieces)) .Returns(false); movementHistory .Setup(h => h.RemoveLastMove()) .Returns(promotionMove); var pieceMover = new PieceMover(movementHistory.Object, promoterMock.Object, castlingMoverMock.Object, enPassantMoverMock.Object); var result = pieceMover.ReverseLastMove(pieces); Assert.AreEqual(pawnMoveBeforePromotion.IsCapture, result); pawnMock .VerifySet(p => p.Position = pawnPreviousPosition); pawnMock .Verify(p => p.DecrementMoveCounter()); movementHistory .Verify(h => h.RemoveLastMove()); }
public BoardViewModel(GameService gameService, MovementService movementService, ISubscriptionProvider subscriptionProvider) { this.gameService = gameService; this.movementService = movementService; this.subscriptionProvider = subscriptionProvider; viewPerspective = ChessColor.White; pieceMover = new PieceMover(); movesSequenceTranslator = new MoveSequenceTranslator(); movesReplayer = MovesReplayer.Create(new MovesLog()); turnsTracker = new TurnsTracker(movesReplayer.MovesLog); }
public void Move(int from, int to) { if (from >= 64) { return; } PieceMover st = SquaresObj[from].GetComponent <PieceMover>(); if (GetPieceAt(from) != Defs.Empty) { st.PieceMouseDown(from); st.PieceMouseUp(to); } }
public void WhenPromotionMoveIsPassed_Move_ReturnsNull() { var movementHistory = new Mock <IMovementHistory>(MockBehavior.Strict); var promoterMock = new Mock <IPiecePromoter>(MockBehavior.Strict); var castlingMoverMock = new Mock <ICastlingMover>(MockBehavior.Strict); var enPassantMoverMock = new Mock <IEnPassantMover>(MockBehavior.Strict); var pieces = new List <IChessPiece>(); var chessMove = new ChessMove(new Position(0, 0), new Position(0, 0), pawnPromotion: ChessPieceType.Knight); promoterMock .Setup(p => p.PromoteIfPromotionMove(chessMove, pieces)) .Returns(true); var pieceMover = new PieceMover(movementHistory.Object, promoterMock.Object, castlingMoverMock.Object, enPassantMoverMock.Object); var result = pieceMover.Move(chessMove, pieces); Assert.AreEqual(null, result); }
public void WhenCastlingMoveWasLast_ReverseLastMove_ReturnsFalse() { var movementHistory = new Mock <IMovementHistory>(MockBehavior.Strict); var promoterMock = new Mock <IPiecePromoter>(MockBehavior.Strict); var castlingMoverMock = new Mock <ICastlingMover>(MockBehavior.Strict); var enPassantMoverMock = new Mock <IEnPassantMover>(MockBehavior.Strict); var pieces = new List <IChessPiece>(); var castlingMove = new ChessMove(new Position(4, 7), new Position(0, 7)); castlingMoverMock .Setup(c => c.UndoCastlingIfCastlingMove(castlingMove, pieces)) .Returns(true); movementHistory .Setup(h => h.RemoveLastMove()) .Returns(castlingMove); var pieceMover = new PieceMover(movementHistory.Object, promoterMock.Object, castlingMoverMock.Object, enPassantMoverMock.Object); var result = pieceMover.ReverseLastMove(pieces); Assert.AreEqual(false, result); }
private void Awake() { Instance = this; _game = GetComponent <Match3>(); }
private void Start() { pieceMover = GetComponent <PieceMover>(); board = FindObjectOfType <Board>(); player = GetComponent <Player>(); }
public void MovePiece(Tile pieceToMove, int desiredRow, int desiredColumn) { PieceMover.MovePiece(this, pieceToMove, desiredRow, desiredColumn); }