private bool CheckEnPassant(IChessBoard board, Move move) { // en passant can only apply on ranks three from the enemies home if (move.Piece.Color == PieceColor.White && move.EndingY != board.Height - 3) { return(false); } if (move.Piece.Color == PieceColor.Black && move.EndingY != 2) { return(false); } // get the piece behind the target move point int forwardDirection = move.Piece.Color == PieceColor.White ? 1 : -1; IChessPiece targetPiece = null; bool targetSquareOccupied = board.TryGetPieceOn(move.EndingX, move.EndingY - forwardDirection, out targetPiece); if (!targetSquareOccupied) { return(false); } if (!(targetPiece is IPawn)) { return(false); } // En Passant can only be applied on the next turn after the piece moves. IPawn pawn = targetPiece as IPawn; return(board.CurrentTurn == pawn.FirstMovedOn + 1); }
public IEnumerable <IField> MoveWithoutCheck(IField fieldStart, IEnumerable <IField> fieldList) // Na nowo to ogarnąć { //Próba 1. Działanie na orginale List <IField> toRemoveList = new List <IField>(); IPawn pawnStart = fieldStart.Pawn; fieldStart.Pawn = null; foreach (IField field in fieldList) { IField fieldBoard = board.FieldList.InThisSamePosition(field); IPawn fieldBoardPaw = fieldBoard.Pawn; fieldBoard.Pawn = pawnStart; bool canBeCheck = MoveRules.IsColorHaveCheck(pawnStart.Color); if (canBeCheck) { toRemoveList.Add(field); } fieldBoard.Pawn = fieldBoardPaw; } fieldStart.Pawn = pawnStart; return(fieldList.Where(w => toRemoveList.InThisSamePosition(w) == null)); }
public PawnPromotionCommand(IList <IChessPiece> pieces, Move move, IPawn movedPawn, IChessPiece takenPiece = null, string promotionType = null) : base(move, movedPawn, takenPiece) { Name = "PawnPromotion"; Pieces = pieces; PromotionType = promotionType; }
public void CheckEnPassant(IPawn pawn, ISquare squaresToMove) { ISquare firstAdjacentSquare = null; ISquare secondAdjacentSquare = null; bool firstCondition = false; bool secondCondition = false; if (squaresToMove.Position.file != 'a') { firstAdjacentSquare = Squares[char.ConvertFromUtf32(squaresToMove.Position.file - 1) + char.GetNumericValue(squaresToMove.Position.rank)]; firstCondition = firstAdjacentSquare.Occupied && firstAdjacentSquare.Piece is IPawn && firstAdjacentSquare.Piece.Player != pawn.Player; } if (squaresToMove.Position.file != 'h') { secondAdjacentSquare = Squares[char.ConvertFromUtf32(squaresToMove.Position.file + 1) + char.GetNumericValue(squaresToMove.Position.rank)]; secondCondition = secondAdjacentSquare.Occupied && secondAdjacentSquare.Piece is IPawn && secondAdjacentSquare.Piece.Player != pawn.Player; } if (firstCondition || secondCondition) { IPawn adjacentPawn = firstCondition ? firstAdjacentSquare.Piece as IPawn : secondAdjacentSquare.Piece as IPawn; ISquare square = pawn.Player.IsPlayer == "Two" ? Squares[squaresToMove.Position.file.ToString() + (char.GetNumericValue(squaresToMove.Position.rank) + 1)] : Squares[squaresToMove.Position.file.ToString() + (char.GetNumericValue(squaresToMove.Position.rank) - 1)]; adjacentPawn.EnPassant = (pawn, square); } }
private void SetLabyrinth() { try { if (!String.IsNullOrWhiteSpace(_pathToFile)) { var lab = _dataLoader.LoadDataFromFile(_pathToFile); if (lab != null) { _score?.Dispose(); _score = new Score(); _playground = new PlayGround(lab); _playgroundRenderer = new PlaygroundRenderer(_playground); _pawn = new ManualMovingPawn(_playground); automatikToolStripMenuItem.Text = AUTOMATIK; Height = _playgroundRenderer.Size.Height; Width = _playgroundRenderer.Size.Width; return; } } _playgroundRenderer = new PlaygroundRenderer(this.Size); } catch (PawnMissingException exception) { MessageBox.Show(exception.Message); } catch (InvalidFormatException exception) { MessageBox.Show(exception.Message); } }
public static List <Move> findAllPossibleLegalCaptureMoves(this IPawn pawn) { Predicate <Square> squareCheckerForCaptureDirections = (Square squareToCheck) => { if (squareToCheck.IsEmpty) { return(false); } else /* if (squareToCheck.isOccupied) */ { return(pawn.Color.GetOpposite() == squareToCheck.Piece.Object.Color); } }; List <Square> captureSquares = pawn.Board.SearchForSquares(squareCheckerForCaptureDirections, pawn.RankAndFile, 1, pawn.LegalCaptureDirections.ToArray()); var captureMoves = new List <Move>(); foreach (var square in captureSquares) { var move = new Move(pawn.Player, pawn, square); captureMoves.Add(move); } return(captureMoves); }
private bool CanPawnMoveForward(GameModel game, IPawn movingPawn, Position destination, Position forwardOne, Position forwardTwo) { if (game.MovingPlayer.Pieces.PieceAtPosition(forwardOne) != null || game.WaitingPlayer.Pieces.PieceAtPosition(forwardOne) != null) { return(false); } if (forwardTwo.Equals(destination)) { if (game.MovesHistory.Any(m => m.MovedPiece == movingPawn)) { return(false); } if (game.MovingPlayer.Pieces.PieceAtPosition(forwardTwo) != null || game.WaitingPlayer.Pieces.PieceAtPosition(forwardTwo) != null) { return(false); } } return(true); }
public void MovePawn_WhenLandingOnBearTrap_IsPlayerSkipTurnTrue() { Pawn = new Pawn(0, 0); Game.BoardTiles.Add(new BearTrapTile(1, 0)); Game.MovePawn(1, Pawn); Assert.IsTrue(Pawn.IsSkippingNextTurn); }
public TurnState CheckIfGameFinished(IPawn pawn) { try { pawn = CurrentPawn; if (pawn.location == _game.Board.size) { GameFinished = true; } else { GameFinished = false; } if (GameFinished == true) { return(TurnState.GameFinished); } else { return(TurnState.TurnFinished); } //GameFinished = CurrentPawn.location == _game.Board.size ? true : false; //return GameFinished == true ? TurnState.GameFinished : TurnState.TurnFinished; } catch { throw new Exception(); } }
public Action(IPawn pawn, int newPosX, int newPosY, int oldPositionX, int oldPositionY, IPawn eatedPawn, int eatedPositionX, int eatedPositionY) { this.pawn = pawn; this.position[0] = newPosX; this.position[1] = newPosY; this.oldPosition[0] = oldPositionX; this.oldPosition[1] = oldPositionY; this.eatedPawn = eatedPawn; this.eatedPosition = new int[]{eatedPositionX, eatedPositionY}; }
void Start() { mainCameraTransform = Camera.main.transform; attachedParent = GetComponentInParent <IPawn>(); healthSlider.minValue = 0; healthSlider.maxValue = attachedParent.MaxHealth; }
public static List <Direction> getLegalCaptureDirections(this IPawn pawn) { if (pawn.Color == black) { return(BlackLegalCaptureDirections); } else /* if (this.color == white) */ { return(WhiteLegalCaptureDirections); } }
//Gets the Pawn with the matching playerID from the Pawns List public IPawn GetPawn() { try { return(CurrentPawn = _game.Board.Pawns.Find(x => x.playerID.Equals(CurrentPlayerID))); } catch (Exception e) { throw new InvalidOperationException($"Nothing Found with PlayerID {CurrentPlayerID} ", e); } }
/// <summary> /// Updates the board after En Passant. Does not check legality. /// </summary> /// <param name="attacker">Pawn that is passing</param> /// <param name="capture">Capture to make</param> /// <param name="lostPiece">Pawn being captured</param> private void UpdateBoardForEnPassant(IPawn attacker, ICapture capture, IPawn lostPiece) { GameBoard.Remove(attacker.Location); attacker.MoveTo(capture.EndingPosition); GameBoard.Add(capture.EndingPosition); GameBoard.Remove(lostPiece.Location); lostPiece.Location = ChessPosition.None; MoveHistory.Add(attacker, capture); }
private void JumpPawnSearchClassic(IPawn root_pawn, Cell root_cell) { var neighbors = root_cell.neighborsCells; if (root_cell.LeftCell != null) { if (root_cell.LeftCell.guestPawn != null) { var cell = root_cell.LeftCell; var list = LeftSearch(root_pawn, cell); foreach (var rc in list) { JumpPawnSearchClassic(root_pawn, rc); } } } if (root_cell.RightCell != null) { if (root_cell.RightCell.guestPawn != null) { var cell = root_cell.RightCell; var list = RightSearch(root_pawn, cell); foreach (var rc in list) { JumpPawnSearchClassic(root_pawn, rc); } } } if (root_cell.UpCell != null) { if (root_cell.UpCell.guestPawn != null) { var cell = root_cell.UpCell; var list = UpSearch(root_pawn, cell); foreach (var rc in list) { JumpPawnSearchClassic(root_pawn, rc); } } } if (root_cell.DownCell != null) { if (root_cell.DownCell.guestPawn != null) { var cell = root_cell.DownCell; var list = DownSearch(root_pawn, cell); foreach (var rc in list) { JumpPawnSearchClassic(root_pawn, rc); } } } }
public void DespawnPawn(IPawn inPawn) { var pawnType = inPawn.GetType(); if (!_pool.ContainsKey(pawnType)) { _pool.Add(pawnType, new List <IPawn>()); } inPawn.WillDespawn(); _pool[pawnType].Add(inPawn); }
private void JumpPawnSearchDiagonals(IPawn root_pawn, Cell root_cell) { var neighbors = root_cell.neighborsCells; if (root_cell.DownLeftCell != null) { if (root_cell.DownLeftCell.guestPawn != null) { var cell = root_cell.DownLeftCell; var list = LeftDownSearch(root_pawn, cell); foreach (var rc in list) { JumpPawnSearchDiagonals(root_pawn, rc); } } } if (root_cell.DownRightCell != null) { if (root_cell.DownRightCell.guestPawn != null) { var cell = root_cell.DownRightCell; var list = RightDownSearch(root_pawn, cell); foreach (var rc in list) { JumpPawnSearchDiagonals(root_pawn, rc); } } } if (root_cell.UpLeftCell != null) { if (root_cell.UpLeftCell.guestPawn != null) { var cell = root_cell.UpLeftCell; var list = LeftUpSearch(root_pawn, cell); foreach (var rc in list) { JumpPawnSearchDiagonals(root_pawn, rc); } } } if (root_cell.UpRightCell != null) { if (root_cell.UpRightCell.guestPawn != null) { var cell = root_cell.UpRightCell; var list = RightUpSearch(root_pawn, cell); foreach (var rc in list) { JumpPawnSearchDiagonals(root_pawn, rc); } } } }
public static Direction getLegalMovementDirectionToEmptySquares(this IPawn pawn) { { if (pawn.Color == black) { return(down); } else /* if (this.color == white) */ { return(up); } } }
public static List <Move> findAllPossibleLegalMoves(this IPawn pawn) { List <Move> legalMoveSquares = pawn.findAllPossibleLegalCaptureMoves(); Optional <Move> emptySquareToMove = pawn.findLegalMovesToEmpty(); if (emptySquareToMove.HasValue) { legalMoveSquares.Add(emptySquareToMove.Object); } return(legalMoveSquares); }
private void CheckSelectedClick(Vector2 clickPoint) { Transform t; int maskPawns = Utils.LayerMaskToInt(pawnsLayer); t = CheckOverlap(clickPoint, maskPawns); if (t != null) { var pawn = t.gameObject.GetComponent <IPawn> (); if (pawn != null) { if (pawn.GetTag() == step) { DeselectAll(); board.DeselectAll(); board.UnCheckedAll(); pawn.SetSelected(true); selectedPawn = pawn; var parentCell = selectedPawn.GetCell(); if (rules == ERules.Classic) { CheckSelectedNonDiagonalNeighbours(parentCell); JumpPawnSearchClassic(pawn, parentCell); } else if (rules == ERules.NoJumpsFourDirs) { CheckSelectedNonDiagonalNeighbours(parentCell); } else if (rules == ERules.NoJumpsAllDirs) { CheckSelectedAllNeighbours(parentCell); } else if (rules == ERules.Diagonals) { CheckSelectedDiagonalNeighbours(parentCell); JumpPawnSearchDiagonals(pawn, parentCell); } else if (rules == ERules.NoJumpsDiagonals) { CheckSelectedDiagonalNeighbours(parentCell); } } } } }
public BreakthroughMoveResults(bool success, IPawn pawnKilled, BoardPosition start, BoardPosition end, bool gameOver, Player winner) { Success = success; GameOver = gameOver; Winner = winner; Path = new List<BoardPosition>(2); Path.Add(start); Path.Add(end); PawnsKilled = new List<IPawn>(1); if (pawnKilled != null) { PawnsKilled.Add(pawnKilled); } }
public void MovePawn_WhenCalled_IsPlayerInCorrectLocation(int roll, int expectedLocationX) { //Arrange Pawn = new Pawn(0, 0); Game.LastNumberRolled = roll; Game.BoardTiles.Add(new BridgeTile(1, 0)); Game.BoardTiles.Add(new SquirrelTile(2, 0)); Game.BoardTiles.Add(new CatapultTile(5, 0)); Game.BoardTiles.Add(new SquirrelTile(6, 1)); //Act Game.MovePawn(roll, Pawn); //Assert Assert.AreEqual(expectedLocationX, Pawn.LocationX); }
public void EnterVehicle(IPawn pawn, VehicleSeatIndex seatIndex, bool @override = false) { if (!(Seats.GetSeat(seatIndex) is VehicleSeat seat)) { return; } if (@override && seat.IsOccupied()) { seat.Occupy(pawn); } else if (seat.IsOccupied()) { seat.Occupy(pawn); } }
public CheckersMoveResults(bool success, bool turnOver, IPawn pawnKilled, BoardPosition start, BoardPosition end, bool gameOver, Player winner, bool becameKing) { Success = success; TurnOver = turnOver; GameOver = gameOver; Winner = winner; Path = new List<BoardPosition>(2); Path.Add(start); Path.Add(end); PawnsKilled = new List<IPawn>(1); if (pawnKilled != null) { PawnsKilled.Add(pawnKilled); } BecameKing = becameKing; }
static void Main(string[] args) { Dictionary <string, IPawn> pawns = new Dictionary <string, IPawn>(); pawns.Add("A1", new Pawn()); pawns.Add("A2", new NullObjectPawn()); IPawn pawn = pawns["A1"]; pawn.Move(); IPawn pawn2 = pawns["A2"]; pawn2.Move(); Console.ReadKey(); }
public virtual void UnPossess() { lock (_possessionLock) { if (_pawn == null) { return; } _pawn = null; EventHandler unPossessedPawn = UnPossessedPawn; if (unPossessedPawn != null) { unPossessedPawn(this, EventArgs.Empty); } } }
private void automatikToolStripMenuItem_Click(object sender, EventArgs e) { if (_pawn != null) { _pawn.Dispose(); if (automatikToolStripMenuItem.Text == AUTOMATIK) { _pawn = new ComputerPlayer(_playground); automatikToolStripMenuItem.Text = MANUAL; } else { _pawn = new ManualMovingPawn(_playground); automatikToolStripMenuItem.Text = AUTOMATIK; } } }
public static Optional <Move> findLegalMovesToEmpty(this IPawn pawn) { Predicate <Square> squareCheckerForMovementDirections = (Square squareToCheck) => { return(squareToCheck.IsEmpty); }; List <Square> availableSquares = pawn.Board.SearchForSquares(squareCheckerForMovementDirections, pawn.RankAndFile, 1, pawn.LegalMovementDirectionToEmptySquares); if (availableSquares.Count > 0) { var move = new Move(pawn.Player, pawn, availableSquares[0]); return(move); } else { return(Optional <Move> .Empty); } }
private List <Cell> RightUpSearch(IPawn root_pawn, Cell cell) { var res = new List <Cell> (); for (var i = 0; i < board.GetWidth(); i++) { if (cell != null) { if (cell.GetCheckedRightUp()) { break; } if (cell.guestPawn == null && cell.DownLeftCell.guestPawn != null) { cell.SetSelected(true); cell.SetCheckedRightUp(true); cell.lastSeenPawn = root_pawn; res.Add(cell); cell = cell.UpRightCell; } else if (cell.UpRightCell != null) { if (cell.UpRightCell.guestPawn == null && cell.guestPawn != null) { cell = cell.UpRightCell; } } else { break; } } else { break; } } return(res); }
private bool GeneralIsChecked(IPawn General) { PlayerSide player = General.GetPlayerSide(); int rowGeneral = player == PlayerSide.BLACK ? rowBlackGeneral : rowRedGeneral; int colGeneral = player == PlayerSide.BLACK ? colBlackGeneral : colRedGeneral; for (int row = 0; row < 10; row++) { for (int col = 0; col < 9; col++) { if (gameBoardPositions[row, col].GetPlayerSide() != PlayerSide.EMPTY && gameBoardPositions[row, col].GetPlayerSide() != player) { if (gameBoardPositions[row, col].CheckMovement(row, col, rowGeneral, colGeneral, gameBoardPositions)) { return(true); } } } } return(false); }
public void MakeMove(string input) { IPawn toPromote = board.PromotionRequired() as IPawn; if (toPromote == null) { MoveParser parser = new MoveParser(); IMove move = parser.Parse(input); IPiece toMove = board.GetFigureAt(move.Start); if (toMove != null && board.CurrentTurn() == toMove.color) { IBoard newBoard = board.Move(move); if (newBoard != null) { board = newBoard; } } } else { Promote(input); } }
public virtual void Possess(IPawn pawn) { if (pawn == null) { throw new ArgumentNullException("pawn"); } lock (_possessionLock) { if (_pawn != null) { UnPossess(); } _pawn = pawn; pawn.OnBecamePossessed(this); EventHandler possessedPawn = PossessedPawn; if (possessedPawn != null) { possessedPawn(this, EventArgs.Empty); } } }
/// <summary> /// Manages the player turn and then the selection of the pawn and the computation of the possible move /// </summary> void PlayerTurn() { if(Input.GetMouseButtonDown(0)){ int[] pos = LocateMouseClick(); if(!IAChess.Const.Types.OutOfBord(pos[0], pos[1])){ if(selectedPawn == null){ selectedPawn = board.GetPawn(pos[0], pos[1]); if(selectedPawn != null && selectedPawn.GetTeam() == -1){ selectedPawn = null; } if(selectedPawn != null){ CheckIfNeedToMoveKing(); selectedHover.localPosition = new Vector3(-3.5f+selectedPawn.GetPosition()[1],3.5f-selectedPawn.GetPosition()[0],0); foreach(Action cAction in selectedPawn.GetPossibleMove()){ possibleMoveHoverInstances.Add((GameObject)GameObject.Instantiate(possibeMoveHover, new Vector3(-3.5f+cAction.position[1],3.5f-cAction.position[0],0), Quaternion.identity)); } } }else{ if(selectedPawn.CanMoveTo(pos[0], pos[1])){ selectedPawn.Move(pos); turn = true; selectedPawn = null; } selectedPawn = null; selectedHover.localPosition = initialSelectedHoverPosition; foreach(object obj in possibleMoveHoverInstances){ GameObject.Destroy((GameObject)obj); } possibleMoveHoverInstances.Clear(); } } } }
/// <summary> /// Initialize all the components of the game. /// </summary> void Start() { _manager = GameObject.FindGameObjectWithTag("GameController").GetComponent<Director>();; initialSelectedHoverPosition = selectedHover.localPosition; for(int i=0; i<IAChess.Const.Types.BOARD_SIZE; i++){ pawns[i] = new IPawn[IAChess.Const.Types.BOARD_SIZE]; pawnsGO[i] = new GameObject[IAChess.Const.Types.BOARD_SIZE]; } CreateEnemyTeam((_manager.team == "White")?Black:White); CreatePlayerTeam((_manager.team == "White")?White:Black); if(_manager.team == "Black") turn = true; board.SetPawns(pawns); _ia = AChessIA.GetIA(board, _manager.difficulty); }
/// <summary> /// Constructs an AI controller with the given pawn /// </summary> /// <param name="pawn"></param> public AIBrain(IPawn pawn) { enemyPawn = pawn; }
/// <summary> /// Util function that check if the player must move the king (because it's under check) /// </summary> void CheckIfNeedToMoveKing() { int[] kingPos = board.PlayerKing.GetPosition(); foreach(IPawn cPawn in board.GetTeam(-1)){ if(cPawn.CanEatIn(kingPos[0], kingPos[1])){ bool found = false; foreach(IPawn pwn in board.GetTeam(1)){ if(pwn.CanEatIn(cPawn.GetPosition()[0], cPawn.GetPosition()[1]) && selectedPawn == pwn){ found = true; break; } } if(!found)selectedPawn = board.PlayerKing; break; } } }
//Fill their reference public void SetPawns(IPawn[][] board) { _board = board; _teams[0] = new List<IPawn>(); _teams[1] = new List<IPawn>(); int i; /* Computer kings*/ i=0; foreach(IPawn cPawn in _board[i]){ if(cPawn != null){ EnemyKing = (King)cPawn; _teams[0].Add(cPawn); cPawn.SetBoard(this); } } /*Computer pawns*/ i=1; foreach(IPawn cPawn in _board[i]){ if(cPawn != null){ _teams[0].Add(cPawn); cPawn.SetBoard(this); } } /*Player King*/ i=7; foreach(IPawn cPawn in _board[i]){ if(cPawn != null){ PlayerKing = (King)cPawn; _teams[1].Add(cPawn); cPawn.SetBoard(this); } } /*Player pawns*/ i=6; foreach(IPawn cPawn in _board[i]){ if(cPawn != null){ _teams[1].Add(cPawn); cPawn.SetBoard(this); } } }
void Start() { mPawn = pawnObj as IPawn; }
public Action(IPawn pawn, int newPosX, int newPosY, int oldPositionX, int oldPositionY) { this.pawn = pawn; this.position[0] = newPosX; this.position[1] = newPosY; this.oldPosition[0] = oldPositionX; this.oldPosition[1] = oldPositionY; }