public Set(Color color) { int rank; this.color = color; pieces = new Piece[16]; rank = (color == Color.Black) ? 8 : 1; pieces[0] = rookA = new Rook(color, new Position(rank, 'a')); pieces[1] = knightA = new Knight(color, new Position(rank, 'b')); pieces[2] = bishopA = new Bishop(color, new Position(rank, 'c')); pieces[3] = king = new King(color, new Position(rank, 'd')); pieces[4] = queen = new Queen(color, new Position(rank, 'e')); pieces[5] = bishopB = new Bishop(color, new Position(rank, 'f')); pieces[6] = knightB = new Knight(color, new Position(rank, 'g')); pieces[7] = rookB = new Rook(color, new Position(rank, 'h')); rank = (color == Color.Black) ? 7 : 2; pieces[8] = pawnA = new Pawn(color, new Position(rank, 'a')); pieces[9] = pawnB = new Pawn(color, new Position(rank, 'b')); pieces[10] = pawnC = new Pawn(color, new Position(rank, 'c')); pieces[11] = pawnD = new Pawn(color, new Position(rank, 'd')); pieces[12] = pawnE = new Pawn(color, new Position(rank, 'e')); pieces[13] = pawnF = new Pawn(color, new Position(rank, 'f')); pieces[14] = pawnG = new Pawn(color, new Position(rank, 'g')); pieces[15] = pawnH = new Pawn(color, new Position(rank, 'h')); }
public List<Tuple<int, int>> getValidMoves(Piece currentPiece, Gameboard gameboard, bool doRecurse = true) { this.copyOfCurrentPiece = new Piece(currentPiece); this.gameboard = new Gameboard(gameboard); switch (currentPiece.type) { case (int)type.rock: // tower Rock rock = new Rock(); this.validDestinations = rock.Rules(currentPiece, gameboard); if (doRecurse) cleanUp(); return validDestinations; case (int)type.knight: // horsie Knight knight = new Knight(); this.validDestinations = knight.Rules(currentPiece, gameboard); if (doRecurse) cleanUp(); return validDestinations; case (int)type.bishop: // springare Bishop bishop = new Bishop(); this.validDestinations = bishop.Rules(currentPiece, gameboard); if (doRecurse) cleanUp(); return validDestinations; case (int)type.queen: //los quuenos Queen queen = new Queen(); this.validDestinations = queen.Rules(currentPiece, gameboard); if (doRecurse) cleanUp(); return validDestinations; case (int)type.king: // los kingos King king = new King(); this.validDestinations = king.Rules(currentPiece, gameboard); if (doRecurse) cleanUp(); return validDestinations; case (int)type.pawn: // los farmeros Pawn pawn = new Pawn(); this.validDestinations = pawn.Rules(currentPiece, gameboard); if (doRecurse) cleanUp(); return validDestinations; } return new List<Tuple<int,int>>(); }
/* * This constructor is used in the clone method */ public List(ArrayList l) { list = new ArrayList(); foreach (Piece p in l) { Position pos = new Position(p.getPosition().getRow(), p.getPosition().getColumn()); Color color = p.getColor(); Image image = p.getImage(); Piece piece = null; if (p is Bishop) { piece = new Bishop(pos, color); } else if (p is Knight) { piece = new Knight(pos, color); } else if (p is Pawn) { piece = new Pawn(pos, color); } else if (p is Queen) { piece = new Queen(pos, color); } else if (p is Rook) { piece = new Rook(pos, color); } else if (p is King) { piece = new King(pos, color); } list.Add(piece); } }
public int canDefend(int color) { Board b = new Board(); Castle castle = new Castle(color, 0, 0); Pawn pawn = new Pawn(color, 0, 0); Knight knight = new Knight(color, 0, 0); Bishop bishop = new Bishop(color, 0, 0); Queen queen = new Queen(color, 0, 0); int i, j, m, n, f = 0; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { b.setSquare(this.getInfo(i, j), i, j); } } Point p = b.searchKing(color); King king = new King(color, p.x, p.y); for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (b.getInfo(i, j) == 0) { } else if (b.getInfo(i, j) == (color == 1 ? 1 : 7)) { castle.x = i; castle.y = j; for (m = 0; m < 8; m++) { for (n = 0; n < 8; n++) { if (castle.move(b, m, n) == 1) { f = b.getInfo(m, n); b.setSquare(0, i, j); b.setSquare((color == 1 ? 1 : 7), m, n); if (king.isChecked(b) == 0) { return(1); } b.setSquare((color == 1 ? 1 : 7), i, j); b.setSquare(f, m, n); } } } } else if (b.getInfo(i, j) == (color == 1 ? 2 : 8)) { knight.x = i; knight.y = j; for (m = 0; m < 8; m++) { for (n = 0; n < 8; n++) { if (knight.move(b, m, n) == 1) { f = b.getInfo(m, n); b.setSquare(0, i, j); b.setSquare((color == 1 ? 2 : 8), m, n); if (king.isChecked(b) == 0) { return(1); } b.setSquare((color == 1 ? 2 : 8), i, j); b.setSquare(f, m, n); } } } } else if (b.getInfo(i, j) == (color == 1 ? 3 : 9)) { bishop.x = i; bishop.y = j; for (m = 0; m < 8; m++) { for (n = 0; n < 8; n++) { if (bishop.move(b, m, n) == 1) { f = b.getInfo(m, n); b.setSquare(0, i, j); b.setSquare((color == 1 ? 3 : 9), m, n); if (king.isChecked(b) == 0) { return(1); } b.setSquare((color == 1 ? 3 : 9), i, j); b.setSquare(f, m, n); } } } } else if (b.getInfo(i, j) == (color == 1 ? 4 : 10)) { queen.x = i; queen.y = j; for (m = 0; m < 8; m++) { for (n = 0; n < 8; n++) { if (queen.move(b, m, n) == 1) { f = b.getInfo(m, n); b.setSquare(0, i, j); b.setSquare((color == 1 ? 4 : 10), m, n); if (king.isChecked(b) == 0) { return(1); } b.setSquare((color == 1 ? 4 : 10), i, j); b.setSquare(f, m, n); } } } } else if (b.getInfo(i, j) == (color == 1 ? 5 : 11)) { for (m = 0; m < 8; m++) { for (n = 0; n < 8; n++) { if (king.move(b, m, n) == 1) { f = b.getInfo(m, n); king.x = m; king.y = n; b.setSquare(0, i, j); b.setSquare((color == 1 ? 5 : 11), m, n); if (king.isChecked(b) == 0) { return(1); } b.setSquare((color == 1 ? 5 : 11), i, j); b.setSquare(f, m, n); king.x = p.x; king.y = p.y; } } } } else if (b.getInfo(i, j) == (color == 1 ? 6 : 12)) { pawn.x = i; pawn.y = j; for (m = 0; m < 8; m++) { for (n = 0; n < 8; n++) { if (pawn.move(b, m, n) == 1) { f = b.getInfo(m, n); b.setSquare(0, i, j); b.setSquare((color == 1 ? 6 : 12), m, n); if (king.isChecked(b) == 0) { return(1); } b.setSquare((color == 1 ? 6 : 12), i, j); b.setSquare(f, m, n); } } } } } } return(0); }
public int isChecked(Board brd2) { int c2, m; if (color == 1) { c2 = 2; } else { c2 = 1; } Board b = brd2; int i, j; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { b.setSquare(brd2.getInfo(i, j), i, j); } } Pawn pawn = new Pawn(c2, 0, 0); Castle castle = new Castle(c2, 0, 0); Knight knight = new Knight(c2, 0, 0); Queen queen = new Queen(c2, 0, 0); Bishop bishop = new Bishop(c2, 0, 0); Point p = brd2.searchKing(color); King king = new King(c2, 0, 0); int r = p.x; int s = p.y; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { m = b.getInfo(i, j); switch (m) { case 0: break; case 1: if (c2 == 1) { castle.x = i; castle.y = j; if (castle.move(b, r, s) == 1) { return(1); } } break; case 2: if (c2 == 1) { knight.x = i; knight.y = j; if (knight.move(b, r, s) == 1) { return(1); } } break; case 3: if (c2 == 1) { bishop.x = i; bishop.y = j; if (bishop.move(b, r, s) == 1) { return(1); } } break; case 4: if (c2 == 1) { queen.x = i; queen.y = j; if (queen.move(b, r, s) == 1) { return(1); } } break; case 5: if (c2 == 2) { king.x = i; king.y = j; if (queen.move(b, r, s) == 1) { return(1); } } break; case 6: if (c2 == 1) { pawn.x = i; pawn.y = j; if (pawn.move(b, r, s) == 1) { return(1); } } break; case 7: if (c2 == 2) { castle.x = i; castle.y = j; if (castle.move(b, r, s) == 1) { return(1); } } break; case 8: if (c2 == 2) { knight.x = i; knight.y = j; if (knight.move(b, r, s) == 1) { return(1); } } break; case 9: if (c2 == 2) { bishop.x = i; bishop.y = j; if (bishop.move(b, r, s) == 1) { return(1); } } break; case 10: if (c2 == 2) { queen.x = i; queen.y = j; if (queen.move(b, r, s) == 1) { return(1); } } break; case 11: if (c2 == 2) { king.x = i; king.y = j; if (king.move(b, r, s) == 1) { return(1); } } break; case 12: if (c2 == 2) { pawn.x = i; pawn.y = j; if (pawn.move(b, r, s) == 1) { return(1); } } break; } } } return(0); }
public void BeforeEachTest() { Target = new Knight(); }
/* Executes a chess move * @param Position from, Position to */ public void ExecuteMove(Position from, Position to) { Piece captured = Move(from, to); if (IsInCheck(CurrentPlayer)) { UndoMove(from, to, captured); throw new GameBoardException("You cannot put yourself in check."); } Piece p = this.Board.GetPiece(to); /*** Promotion ***/ if (p is Pawn) { if ((p.Color == Color.White && to.Row == 0) || (p.Color == Color.Black && to.Row == 7)) { p = this.Board.RemovePiece(to); this._pieces.Remove(p); bool wrong = true; Piece np = null; do { Console.Clear(); View.PrintMatch(this, null); Console.WriteLine("PROMOTION\n" + "Knight [N/n]\n" + "Rook [R/r]\n" + "Bishop [B/b]\n" + "Queen [Q/q]\n" + "Choose a piece: "); string c = Console.ReadLine(); switch (c.ToUpper()) { case "N": np = new Knight(p.Color, this.Board); wrong = false; break; case "R": np = new Rook(p.Color, this.Board); wrong = false; break; case "B": np = new Bishop(p.Color, this.Board); wrong = false; break; case "Q": np = new Queen(p.Color, this.Board); wrong = false; break; default: Console.WriteLine("Invalid Piece!" + "\nPress enter to continue..."); Console.ReadLine(); wrong = true; break; } } while (wrong); this.Board.InsertPiece(np, to); this._pieces.Add(np); } } if (IsInCheck(Opponent(CurrentPlayer))) { this.Check = true; } else { this.Check = false; } if (IsInCheckmate(Opponent(CurrentPlayer))) { this.Finished = true; } else { this.Turn++; SwitchPlayers(); } /*** En Passant ***/ if (p is Pawn && (to.Row == from.Row - 2 || to.Row == from.Row + 2)) { this.EnPassant = p; } else { this.EnPassant = null; } }
public void KnightShouldBeInCorrectMove() { ChessFigure figure = new Knight("b1"); Assert.AreEqual(false, figure.Move("c5")); }
public void promotePawn(ContentManager c) { for (int i = 0; i < 8; i++) { if (Pieces[i] != null) { if (Pieces[i].Position.RowInBoard == 7 && Pieces[i] is Pawn) { PromotionForm p = new PromotionForm(); drawPiecesInForm(false); Game1.pf.ShowDialog(); if (Game1.pf.isClicked) { switch (Game1.pf.choice) { case PromotionChoices.Queen: Game1.pf.Close(); Pieces[i] = new Queen(false, Pieces[i].Position); Pieces[i].Position.PieceInside = Pieces[i]; Pieces[i].loadTexture(c); break; case PromotionChoices.Rook: Game1.pf.Close(); Pieces[i] = new Rook(false, Pieces[i].Position); Pieces[i].Position.PieceInside = Pieces[i]; Pieces[i].loadTexture(c); break; case PromotionChoices.Bishop: Game1.pf.Close(); Pieces[i] = new Bishop(false, Pieces[i].Position); Pieces[i].Position.PieceInside = Pieces[i]; Pieces[i].loadTexture(c); break; case PromotionChoices.Knight: Game1.pf.Close(); Pieces[i] = new Knight(false, Pieces[i].Position); Pieces[i].Position.PieceInside = Pieces[i]; Pieces[i].loadTexture(c); break; } } /*Pieces[i] = new Queen(false, Pieces[i].Position); * Pieces[i].Position.PieceInside = Pieces[i]; * Pieces[i].loadTexture(c);*/ } } if (Pieces[i + 8] != null) { if (Pieces[i + 8].Position.RowInBoard == 0 && Pieces[i + 8] is Pawn) { PromotionForm p = new PromotionForm(); drawPiecesInForm(true); Game1.pf.ShowDialog(); if (Game1.pf.isClicked) { switch (Game1.pf.choice) { case PromotionChoices.Queen: Game1.pf.Close(); Pieces[i + 8] = new Queen(true, Pieces[i + 8].Position); Pieces[i + 8].Position.PieceInside = Pieces[i + 8]; Pieces[i + 8].loadTexture(c); break; case PromotionChoices.Rook: Game1.pf.Close(); Pieces[i + 8] = new Rook(true, Pieces[i + 8].Position); Pieces[i + 8].Position.PieceInside = Pieces[i + 8]; Pieces[i + 8].loadTexture(c); break; case PromotionChoices.Bishop: Game1.pf.Close(); Pieces[i + 8] = new Bishop(true, Pieces[i + 8].Position); Pieces[i + 8].Position.PieceInside = Pieces[i + 8]; Pieces[i + 8].loadTexture(c); break; case PromotionChoices.Knight: Game1.pf.Close(); Pieces[i + 8] = new Knight(true, Pieces[i + 8].Position); Pieces[i + 8].Position.PieceInside = Pieces[i + 8]; Pieces[i + 8].loadTexture(c); break; } } /*Pieces[ i + 8] = new Queen(true, Pieces[ i + 8].Position); * Pieces[i + 8].Position.PieceInside = Pieces[i + 8]; * Pieces[ i + 8].loadTexture(c);*/ } } } }
public void KnightShouldBeIncorrectMove() { var figure = new Knight("B1"); Assert.AreEqual(false, figure.Move("C5")); }
public void MakeMove(Position origin, Position destiny) { Piece takenPiece = ChessMove(origin, destiny); if (IsInCheck(CurrentPlayer)) { UndoChessMove(origin, destiny, takenPiece); throw new BoardExceptions("You can not put your self in check"); } Piece movedPiece = Board.GetPiece(destiny); //Special move: Pawn Promotion if (movedPiece is Pawn) { if ((movedPiece.Color == Color.White && destiny.Line == 0) || (movedPiece.Color == Color.Black && destiny.Line == 7)) { Board.RemovePiece(destiny); GamePieces.Remove(movedPiece); Console.WriteLine("Type the kind of piece you want to promote your pawn to"); Console.Write("(QUEEN / ROOK / KNIGHT / BISHOP): "); string playerChoice = Console.ReadLine(); if (!ScreenController.CheckPlayerChoice(playerChoice)) { throw new BoardExceptions("Not valid option"); } playerChoice = playerChoice.ToLower(); switch (playerChoice) { case "queen": { Piece newPiece = new Queen(movedPiece.Color, Board); Board.AddressPiece(newPiece, destiny); GamePieces.Add(newPiece); break; } case "rook": { Piece newPiece = new Rook(movedPiece.Color, Board); Board.AddressPiece(newPiece, destiny); GamePieces.Add(newPiece); break; } case "knight": { Piece newPiece = new Knight(movedPiece.Color, Board); Board.AddressPiece(newPiece, destiny); GamePieces.Add(newPiece); break; } case "bishop": { Piece newPiece = new Bishop(movedPiece.Color, Board); Board.AddressPiece(newPiece, destiny); GamePieces.Add(newPiece); break; } } } } //EndGame Pawn Promotion if (IsInCheck(EnemyIs(CurrentPlayer))) { PlayerInCheck = true; } else { PlayerInCheck = false; } if (IsInCheckMate(EnemyIs(CurrentPlayer))) { EndGame = true; } else { Turn++; MudaJogador(); } //Special move: en passant if (movedPiece is Pawn && (destiny.Line == origin.Line + 2 || destiny.Line == origin.Line - 2)) { VulnerableToEnPassant = movedPiece; } else { VulnerableToEnPassant = null; } }
/** * StartGame() * * Remplit le plateau et lance le premier tour * * @author Axel Floquet-Trillot * */ public void StartGame() { //Remplissage du plateau for (int i = 0; i < GameBoard.GetLength(0); i++) { switch (i) { case 0: for (int j = 0; j < GameBoard.GetLength(1); j++) { switch (j) { case 0: case 7: GameBoard[i, j] = new Rook(Piece.Color.Black); break; case 1: case 6: GameBoard[i, j] = new Knight(Piece.Color.Black); break; case 2: case 5: GameBoard[i, j] = new Bishop(Piece.Color.Black); break; case 3: GameBoard[i, j] = new Queen(Piece.Color.Black); break; case 4: GameBoard[i, j] = new King(Piece.Color.Black); break; } } break; case 1: for (int j = 0; j < GameBoard.GetLength(1); j++) { GameBoard[i, j] = new Pawn(Piece.Color.Black); } break; case 2: case 3: case 4: case 5: for (int j = 0; j < GameBoard.GetLength(1); j++) { GameBoard[i, j] = null; } break; case 6: for (int j = 0; j < GameBoard.GetLength(1); j++) { GameBoard[i, j] = new Pawn(Piece.Color.White); } break; case 7: for (int j = 0; j < GameBoard.GetLength(1); j++) { switch (j) { case 0: case 7: GameBoard[i, j] = new Rook(Piece.Color.White); break; case 1: case 6: GameBoard[i, j] = new Knight(Piece.Color.White); break; case 2: case 5: GameBoard[i, j] = new Bishop(Piece.Color.White); break; case 3: GameBoard[i, j] = new Queen(Piece.Color.White); break; case 4: GameBoard[i, j] = new King(Piece.Color.White); break; } } break; } } PlayTurn(); }
private void buttonAccept_Click(object sender, System.EventArgs e) { //Button "Accept" clicked, carry out the promotion if (comboBoxFigures.SelectedItem == null) { MessageBox.Show(this, "You must select a figure", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { promotionRealized = true; //Delete the pawn Board.getInstance().killPiece(pawn.getPosition(), true); //Create the new figure string fig = comboBoxFigures.SelectedItem.ToString(); Position pos = pawn.getPosition(); Color color = pawn.getColor(); Piece piece = null; if (fig == "Bishop") { piece = new Bishop(pos, color); } else if (fig == "Knight") { piece = new Knight(pos, color); } else if (fig == "Queen") { piece = new Queen(pos, color); } else if (fig == "Rook") { piece = new Rook(pos, color); } if (color == Color.White) { Board.getInstance().getWhitePieces().insert(piece); } else { Board.getInstance().getBlackPieces().insert(piece); } Board.getInstance().deletePiece(pawn); Board.getInstance().drawPiece(piece); this.Close(); } }
public bool MatetestforWhite(GameBoard Game, Empty Emptyspace, Check Checker) { Coordinate CurrentCoord = new Coordinate(); Coordinate NextCoord = new Coordinate(); for (int i = 0; i < Game.White.Count; i++) { string typecheck = Game.White[i].GetType().ToString(); CurrentCoord.X = Game.White[i].Current.X; CurrentCoord.Y = Game.White[i].Current.Y; for (byte j = 0; j < 8; j++) { NextCoord.X = j; for (byte k = 0; k < 8; k++) { NextCoord.Y = k; switch (typecheck) { case "Chess.Pawn": Pawn Pawnmover = new Pawn("WHITE"); Pawnmover = (Pawn)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y]; if (Pawnmover.isMovable(Game, NextCoord)) { Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace); if (!(Checker.Checktest(Game, NextCoord))) { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); } else { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); return(true); } } break; case "Chess.Bishop": Bishop Bishopmover = new Bishop("a"); Bishopmover = (Bishop)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y]; if (Bishopmover.isMovable(Game, NextCoord)) { Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace); if (!(Checker.Checktest(Game, NextCoord))) { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); } else { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); return(true); } } break; case "Chess.Queen": Queen Queenmover = new Queen("a"); Queenmover = (Queen)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y]; if (Queenmover.isMovable(Game, NextCoord)) { Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace); if (!(Checker.Checktest(Game, NextCoord))) { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); } else { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); return(true); } } break; case "Chess.Knight": Knight Knightmover = new Knight("a"); Knightmover = (Knight)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y]; if (Knightmover.isMovable(Game, NextCoord)) { Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace); if (!(Checker.Checktest(Game, NextCoord))) { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); } else { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); return(true); } } break; case "Chess.Castle": Castle Castlemover = new Castle("a"); Castlemover = (Castle)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y]; if (Castlemover.isMovable(Game, NextCoord)) { Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace); if (!(Checker.Checktest(Game, NextCoord))) { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); } else { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); return(true); } } break; case "Chess.King": King Kingmover = new King("a"); Kingmover = (King)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y]; if (Kingmover.isMovable(Game, NextCoord)) { Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace); if (!(Checker.Checktest(Game, NextCoord))) { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); } else { Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace); return(true); } } break; } } } } return(false); }
public List <Move> GetKnightMovement(Knight piece) { var moves = new List <Move>(); var xPosition1 = piece.xPostion + 2; var yPosition1 = piece.yPostion + 1; var move = GetMoveIfPossible(piece, xPosition1, yPosition1, out Piece capturedPiece); if (move != null) { moves.Add(move); } var xPosition2 = piece.xPostion + 2; var yPosition2 = piece.yPostion - 1; move = GetMoveIfPossible(piece, xPosition2, yPosition2, out capturedPiece); if (move != null) { moves.Add(move); } var xPosition3 = piece.xPostion - 2; var yPosition3 = piece.yPostion + 1; move = GetMoveIfPossible(piece, xPosition3, yPosition3, out capturedPiece); if (move != null) { moves.Add(move); } var xPosition4 = piece.xPostion - 2; var yPosition4 = piece.yPostion - 1; move = GetMoveIfPossible(piece, xPosition4, yPosition4, out capturedPiece); if (move != null) { moves.Add(move); } var xPosition5 = piece.xPostion + 1; var yPosition5 = piece.yPostion + 2; move = GetMoveIfPossible(piece, xPosition5, yPosition5, out capturedPiece); if (move != null) { moves.Add(move); } var xPosition6 = piece.xPostion + 1; var yPosition6 = piece.yPostion - 2; move = GetMoveIfPossible(piece, xPosition6, yPosition6, out capturedPiece); if (move != null) { moves.Add(move); } var xPosition7 = piece.xPostion - 1; var yPosition7 = piece.yPostion + 2; move = GetMoveIfPossible(piece, xPosition7, yPosition7, out capturedPiece); if (move != null) { moves.Add(move); } var xPosition8 = piece.xPostion - 1; var yPosition8 = piece.yPostion - 2; move = GetMoveIfPossible(piece, xPosition8, yPosition8, out capturedPiece); if (move != null) { moves.Add(move); } return(moves); }
private void MoveFigure(int x, int y, int xNew, int yNew, Figure[,] table = null) { if (table == null) { table = figureTable; } else { table = tempTable; } Figure oldFigure = table[x, y]; oldFigure.Move(xNew, yNew); if (table == figureTable) { previousMove = new Tuple <PlayerType, FigureType, int, int, int, int>(onMove, oldFigure.type, x, y, xNew, yNew); } if (table[x, y] != null && table[x, y] is Pawn) { Pawn pawn = table[x, y] as Pawn; // Check if en passant if (xNew == x + pawn.Direction && (yNew == y - 1 || yNew == y + 1) && table[xNew, yNew] == null) { table[x, yNew] = null; } table[xNew, yNew] = oldFigure; table[x, y] = null; // Check for promotion (Upgrade this code!!!) - only in real move mode if (table == figureTable && (xNew == 0 || xNew == 7)) { new Promotion(onMove).ShowDialog(); FigureType promotionFigure = Promotion.promotedFigure; switch (promotionFigure) { case FigureType.KNIGHT: table[xNew, yNew] = new Knight(xNew, yNew, onMove, promotionFigure, this); break; case FigureType.BISHOP: table[xNew, yNew] = new Bishop(xNew, yNew, onMove, promotionFigure, this); break; case FigureType.ROOK: table[xNew, yNew] = new Rook(xNew, yNew, onMove, promotionFigure, this); break; case FigureType.QUEEN: table[xNew, yNew] = new Queen(xNew, yNew, onMove, promotionFigure, this); break; default: break; } } } // Rokada (Castling) else if (table == figureTable && table[x, y] != null && table[x, y] is King && Math.Abs(yNew - y) == 2) { // Move king table[xNew, yNew] = oldFigure; table[x, y] = null; // Small - move rook if (yNew > y) { table[x, yNew + 1].Move(x, yNew - 1); table[x, yNew - 1] = table[x, yNew + 1]; table[x, yNew + 1] = null; } // Big - move rook else { table[x, yNew - 2].Move(x, yNew + 1); table[x, yNew + 1] = table[x, yNew - 2]; table[x, yNew - 2] = null; } } else { table[xNew, yNew] = oldFigure; table[x, y] = null; } }
public void CreateDefaultPosition() { Figure blackCastle1 = new Castle(false, 0, 0); Figure blackCastle2 = new Castle(false, 7, 0); Figure blackKnight1 = new Knight(false, 1, 0); Figure blackKnight2 = new Knight(false, 6, 0); Figure blackBishop1 = new Bishop(false, 2, 0); Figure blackBishop2 = new Bishop(false, 5, 0); Figure blackKing = new King(false, 4, 0); Figure blackQueen = new Queen(false, 3, 0); Figure blackPawn1 = new Pawn(false, 0, 1); Figure blackPawn2 = new Pawn(false, 1, 1); Figure blackPawn3 = new Pawn(false, 2, 1); Figure blackPawn4 = new Pawn(false, 3, 1); Figure blackPawn5 = new Pawn(false, 4, 1); Figure blackPawn6 = new Pawn(false, 5, 1); Figure blackPawn7 = new Pawn(false, 6, 1); Figure blackPawn8 = new Pawn(false, 7, 1); Figure whiteCastle1 = new Castle(true, 0, 7); Figure whiteCastle2 = new Castle(true, 7, 7); Figure whiteKnight1 = new Knight(true, 1, 7); Figure whiteKnight2 = new Knight(true, 6, 7); Figure whiteBishop1 = new Bishop(true, 2, 7); Figure whiteBishop2 = new Bishop(true, 5, 7); Figure whiteKing = new King(true, 4, 7); Figure whiteQueen = new Queen(true, 3, 7); Figure whitePawn1 = new Pawn(true, 0, 6); Figure whitePawn2 = new Pawn(true, 1, 6); Figure whitePawn3 = new Pawn(true, 2, 6); Figure whitePawn4 = new Pawn(true, 3, 6); Figure whitePawn5 = new Pawn(true, 4, 6); Figure whitePawn6 = new Pawn(true, 5, 6); Figure whitePawn7 = new Pawn(true, 6, 6); Figure whitePawn8 = new Pawn(true, 7, 6); _table[0, 0].PutFigure(blackCastle1); _table[1, 0].PutFigure(blackKnight1); _table[2, 0].PutFigure(blackBishop1); _table[3, 0].PutFigure(blackQueen); _table[4, 0].PutFigure(blackKing); _table[5, 0].PutFigure(blackBishop2); _table[6, 0].PutFigure(blackKnight2); _table[7, 0].PutFigure(blackCastle2); _table[0, 1].PutFigure(blackPawn1); _table[1, 1].PutFigure(blackPawn2); _table[2, 1].PutFigure(blackPawn3); _table[3, 1].PutFigure(blackPawn4); _table[4, 1].PutFigure(blackPawn5); _table[5, 1].PutFigure(blackPawn6); _table[6, 1].PutFigure(blackPawn7); _table[7, 1].PutFigure(blackPawn8); _table[0, 7].PutFigure(whiteCastle1); _table[1, 7].PutFigure(whiteKnight1); _table[2, 7].PutFigure(whiteBishop1); _table[3, 7].PutFigure(whiteQueen); _table[4, 7].PutFigure(whiteKing); _table[5, 7].PutFigure(whiteBishop2); _table[6, 7].PutFigure(whiteKnight2); _table[7, 7].PutFigure(whiteCastle2); _table[0, 6].PutFigure(whitePawn1); _table[1, 6].PutFigure(whitePawn2); _table[2, 6].PutFigure(whitePawn3); _table[3, 6].PutFigure(whitePawn4); _table[4, 6].PutFigure(whitePawn5); _table[5, 6].PutFigure(whitePawn6); _table[6, 6].PutFigure(whitePawn7); _table[7, 6].PutFigure(whitePawn8); }
static void StartPlacement(Cell[,] Field) { King WhiteKing = new King(1, '♚', 7, 4); WhiteKing.SetToCell(Field, 7, 4); WhiteKing.SetFigureColor(Field, 7, 4); King BlackKing = new King(0, '♚', 0, 4); BlackKing.SetToCell(Field, 0, 4); BlackKing.SetFigureColor(Field, 0, 4); Quinn WhiteQuinn = new Quinn(1, '♛', 7, 3); WhiteQuinn.SetToCell(Field, 7, 3); WhiteQuinn.SetFigureColor(Field, 7, 3); Quinn BlackQuinn = new Quinn(0, '♛', 0, 3); BlackQuinn.SetToCell(Field, 0, 3); BlackQuinn.SetFigureColor(Field, 0, 3); Bishop WhiteBishop1 = new Bishop(1, '♝', 7, 2); WhiteBishop1.SetToCell(Field, 7, 2); WhiteBishop1.SetFigureColor(Field, 7, 2); Bishop WhiteBishop2 = new Bishop(1, '♝', 7, 5); WhiteBishop2.SetToCell(Field, 7, 5); WhiteBishop2.SetFigureColor(Field, 7, 5); Bishop BlackBishop1 = new Bishop(0, '♝', 0, 2); BlackBishop1.SetToCell(Field, 0, 2); BlackBishop1.SetFigureColor(Field, 0, 2); Bishop BlackBishop2 = new Bishop(0, '♝', 0, 5); BlackBishop2.SetToCell(Field, 0, 5); BlackBishop2.SetFigureColor(Field, 0, 5); Knight WhiteKnight1 = new Knight(1, '♞', 7, 1); WhiteKnight1.SetToCell(Field, 7, 1); WhiteKnight1.SetFigureColor(Field, 7, 1); Knight WhiteKnight2 = new Knight(1, '♞', 7, 6); WhiteKnight2.SetToCell(Field, 7, 6); WhiteKnight2.SetFigureColor(Field, 7, 6); Knight BlackKnight1 = new Knight(0, '♞', 0, 1); BlackKnight1.SetToCell(Field, 0, 1); BlackKnight1.SetFigureColor(Field, 0, 1); Knight BlackKnight2 = new Knight(0, '♞', 0, 6); BlackKnight2.SetToCell(Field, 0, 6); BlackKnight2.SetFigureColor(Field, 0, 6); Rook WhiteRook1 = new Rook(1, '♜', 7, 0); WhiteRook1.SetToCell(Field, 7, 0); WhiteRook1.SetFigureColor(Field, 7, 0); Rook WhiteRook2 = new Rook(1, '♜', 7, 7); WhiteRook2.SetToCell(Field, 7, 7); WhiteRook2.SetFigureColor(Field, 7, 7); Rook BlackRook1 = new Rook(0, '♜', 0, 0); BlackRook1.SetToCell(Field, 0, 0); BlackRook1.SetFigureColor(Field, 0, 0); Rook BlackRook2 = new Rook(0, '♜', 0, 7); BlackRook2.SetToCell(Field, 0, 7); BlackRook2.SetFigureColor(Field, 0, 7); Pawn WhitePawn1 = new Pawn(1, '♟', 6, 0); WhitePawn1.SetToCell(Field, 6, 0); WhitePawn1.SetFigureColor(Field, 6, 0); Pawn WhitePawn2 = new Pawn(1, '♟', 6, 1); WhitePawn2.SetToCell(Field, 6, 1); WhitePawn2.SetFigureColor(Field, 6, 1); Pawn WhitePawn3 = new Pawn(1, '♟', 6, 2); WhitePawn3.SetToCell(Field, 6, 2); WhitePawn3.SetFigureColor(Field, 6, 2); Pawn WhitePawn4 = new Pawn(1, '♟', 6, 3); WhitePawn4.SetToCell(Field, 6, 3); WhitePawn4.SetFigureColor(Field, 6, 3); Pawn WhitePawn5 = new Pawn(1, '♟', 6, 4); WhitePawn5.SetToCell(Field, 6, 4); WhitePawn5.SetFigureColor(Field, 6, 4); Pawn WhitePawn6 = new Pawn(1, '♟', 6, 5); WhitePawn6.SetToCell(Field, 6, 5); WhitePawn6.SetFigureColor(Field, 6, 5); Pawn WhitePawn7 = new Pawn(1, '♟', 6, 6); WhitePawn7.SetToCell(Field, 6, 6); WhitePawn7.SetFigureColor(Field, 6, 6); Pawn WhitePawn8 = new Pawn(1, '♟', 6, 7); WhitePawn8.SetToCell(Field, 6, 7); WhitePawn8.SetFigureColor(Field, 6, 7); Pawn BlackPawn1 = new Pawn(0, '♟', 1, 0); BlackPawn1.SetToCell(Field, 1, 0); BlackPawn1.SetFigureColor(Field, 1, 0); Pawn BlackPawn2 = new Pawn(0, '♟', 1, 1); BlackPawn2.SetToCell(Field, 1, 1); Pawn BlackPawn3 = new Pawn(0, '♟', 1, 2); BlackPawn3.SetToCell(Field, 1, 2); Pawn BlackPawn4 = new Pawn(0, '♟', 1, 3); BlackPawn4.SetToCell(Field, 1, 3); Pawn BlackPawn5 = new Pawn(0, '♟', 1, 4); BlackPawn5.SetToCell(Field, 1, 4); Pawn BlackPawn6 = new Pawn(0, '♟', 1, 5); BlackPawn6.SetToCell(Field, 1, 5); Pawn BlackPawn7 = new Pawn(0, '♟', 1, 6); BlackPawn7.SetToCell(Field, 1, 6); Pawn BlackPawn8 = new Pawn(0, '♟', 1, 7); BlackPawn8.SetToCell(Field, 1, 7); }
public bool ChecktestforRookBlack(GameBoard _Game, byte _X, byte _Y) { int i; for (i = 0; i < _Game.White.Count; i++) { Coordinate _Next = new Coordinate(_X, _Y); string typecheck = _Game.White[i].GetType().ToString(); switch (typecheck) { case "Chess.Pawn": Pawn Pawnmover = new Pawn("a"); Pawnmover = (Pawn)_Game.White[i]; if (Pawnmover.isMovable(_Game, _Next)) { return(true); } break; case "Chess.Bishop": Bishop Bishopmover = new Bishop("a"); Bishopmover = (Bishop)_Game.White[i]; if (Bishopmover.isMovable(_Game, _Next)) { return(true); } break; case "Chess.Queen": Queen Queenmover = new Queen("a"); Queenmover = (Queen)_Game.White[i]; if (Queenmover.isMovable(_Game, _Next)) { return(true); } break; case "Chess.Knight": Knight Knightmover = new Knight("a"); Knightmover = (Knight)_Game.White[i]; if (Knightmover.isMovable(_Game, _Next)) { return(true); } break; case "Chess.Castle": Castle Castlemover = new Castle("a"); Castlemover = (Castle)_Game.White[i]; if (Castlemover.isMovable(_Game, _Next)) { return(true); } break; case "Chess.King": King Kingmover2 = new King("a"); Kingmover2 = (King)_Game.White[i]; if (Kingmover2.isMovable(_Game, _Next)) { return(true); } break; } } return(false); }
public void placeWhiteFigures(bool isStandardChess) { Figure[] pawns = new Figure[8]; char currentChar = 'A'; char charPositionPawn = 'A'; if (isStandardChess) { for (int i = 0; i < 8; i++) { pawns[i] = new Pawn(charPositionPawn, 7, true); charPositionPawn++; if ((currentChar == 'A') || (currentChar == 'H')) { otherFigures[i] = new Rook(currentChar, 8, true); } else if ((currentChar == 'B') || (currentChar == 'G')) { otherFigures[i] = new Knight(currentChar, 8, true); } else if ((currentChar == 'C') || (currentChar == 'F')) { otherFigures[i] = new Bishop(currentChar, 8, true); } else if (currentChar == 'E') { otherFigures[i] = new King(currentChar, 8, true); } else { otherFigures[i] = new Queen(currentChar, 8, true); } currentChar++; } for (int i = 0; i < 8; i++) { placeFigure(pawns[i]); placeFigure(otherFigures[i]); } } else if (!isStandardChess) { for (int i = 0; i < 8; i++) { pawns[i] = new Pawn(charPositionPawn, 7, true); charPositionPawn++; currentChar++; } do { char[] piecePlacement = boardSpaces.OrderBy(x => random.Next()).ToArray(); otherFigures[0] = new Bishop(piecePlacement[0], 8, true); otherFigures[1] = new Bishop(piecePlacement[1], 8, true); otherFigures[2] = new Rook(piecePlacement[2], 8, true); otherFigures[3] = new Rook(piecePlacement[3], 8, true); otherFigures[4] = new Knight(piecePlacement[4], 8, true); otherFigures[5] = new Knight(piecePlacement[5], 8, true); otherFigures[6] = new Queen(piecePlacement[6], 8, true); otherFigures[7] = new King(piecePlacement[7], 8, true); if (!(otherFigures[0].Xpositon % 2 == otherFigures[1].Xpositon % 2) && (((otherFigures[2].Xpositon > otherFigures[7].Xpositon) && (otherFigures[3].Xpositon < otherFigures[7].Xpositon)) || ((otherFigures[2].Xpositon < otherFigures[7].Xpositon) && (otherFigures[3].Xpositon > otherFigures[7].Xpositon)))) { valid = true; } } while (!valid); for (int i = 0; i < 8; i++) { placeFigure(pawns[i]); placeFigure(otherFigures[i]); } placeBlackFigures(isStandardChess); } }
public void SetupBoard(string setup) { switch (setup) { case "new_game_setup": // WEISSE SPIELFIGUREN PawnWhite pawn_w_1 = factory.GetPawnWhite("A2"); PawnWhite pawn_w_2 = factory.GetPawnWhite("B2"); PawnWhite pawn_w_3 = factory.GetPawnWhite("C2"); PawnWhite pawn_w_4 = factory.GetPawnWhite("D2"); PawnWhite pawn_w_5 = factory.GetPawnWhite("E2"); PawnWhite pawn_w_6 = factory.GetPawnWhite("F2"); PawnWhite pawn_w_7 = factory.GetPawnWhite("G2"); PawnWhite pawn_w_8 = factory.GetPawnWhite("H2"); Rook rook_w_1 = factory.GetRook("white", "A1"); Knight knight_w_1 = factory.GetKnight("white", "B1"); Bishop bishop_w_1 = factory.GetBishop("white", "C1"); Queen queen_w = factory.GetQueen("white", "D1"); King king_w = factory.GetKing("white", "E1"); Bishop bishop_w_2 = factory.GetBishop("white", "F1"); Knight knight_w_2 = factory.GetKnight("white", "G1"); Rook rook_w_2 = factory.GetRook("white", "H1"); // SCHWARZE SPIELFIGUREN PawnBlack pawn_b_1 = factory.GetPawnBlack("A7"); PawnBlack pawn_b_2 = factory.GetPawnBlack("B7"); PawnBlack pawn_b_3 = factory.GetPawnBlack("C7"); PawnBlack pawn_b_4 = factory.GetPawnBlack("D7"); PawnBlack pawn_b_5 = factory.GetPawnBlack("E7"); PawnBlack pawn_b_6 = factory.GetPawnBlack("F7"); PawnBlack pawn_b_7 = factory.GetPawnBlack("G7"); PawnBlack pawn_b_8 = factory.GetPawnBlack("H7"); Rook rook_b_1 = factory.GetRook("black", "A8"); Knight knight_b_1 = factory.GetKnight("black", "B8"); Bishop bishop_b_1 = factory.GetBishop("black", "C8"); Queen queen_b = factory.GetQueen("black", "D8"); King king_b = factory.GetKing("black", "E8"); Bishop bishop_b_2 = factory.GetBishop("black", "F8"); Knight knight_b_2 = factory.GetKnight("black", "G8"); Rook rook_b_2 = factory.GetRook("black", "H8"); // WEISSE SPIELFIGUREN board.chessman.Add(pawn_w_1); board.chessman.Add(pawn_w_2); board.chessman.Add(pawn_w_3); board.chessman.Add(pawn_w_4); board.chessman.Add(pawn_w_5); board.chessman.Add(pawn_w_6); board.chessman.Add(pawn_w_7); board.chessman.Add(pawn_w_8); board.chessman.Add(rook_w_1); board.chessman.Add(rook_w_2); board.chessman.Add(bishop_w_1); board.chessman.Add(bishop_w_2); board.chessman.Add(knight_w_1); board.chessman.Add(knight_w_2); board.chessman.Add(queen_w); board.chessman.Add(king_w); // SCHWARZE SPIELFIGUREN board.chessman.Add(pawn_b_1); board.chessman.Add(pawn_b_2); board.chessman.Add(pawn_b_3); board.chessman.Add(pawn_b_4); board.chessman.Add(pawn_b_5); board.chessman.Add(pawn_b_6); board.chessman.Add(pawn_b_7); board.chessman.Add(pawn_b_8); board.chessman.Add(rook_b_1); board.chessman.Add(rook_b_2); board.chessman.Add(bishop_b_1); board.chessman.Add(bishop_b_2); board.chessman.Add(knight_b_1); board.chessman.Add(knight_b_2); board.chessman.Add(queen_b); board.chessman.Add(king_b); break; case "promotion_setup": // WEISSE SPIELFIGUREN PawnWhite promotion_pawn_w_1 = factory.GetPawnWhite("A7"); PawnWhite promotion_pawn_w_2 = factory.GetPawnWhite("B7"); King promotion_king_w = factory.GetKing("white", "E1"); Bishop promotion_bishop_w_2 = factory.GetBishop("white", "F1"); Knight promotion_knight_w_2 = factory.GetKnight("white", "G1"); Rook promotion_rook_w_2 = factory.GetRook("white", "H1"); // SCHWARZE SPIELFIGUREN PawnBlack promotion_pawn_b_1 = factory.GetPawnBlack("A2"); PawnBlack promotion_pawn_b_2 = factory.GetPawnBlack("B2"); King promotion_king_b = factory.GetKing("black", "E8"); Bishop promotion_bishop_b_2 = factory.GetBishop("black", "F8"); Knight promotion_knight_b_2 = factory.GetKnight("black", "G8"); Rook promotion_rook_b_2 = factory.GetRook("black", "H8"); // WEISSE SPIELFIGUREN board.chessman.Add(promotion_pawn_w_1); board.chessman.Add(promotion_pawn_w_2); board.chessman.Add(promotion_king_w); board.chessman.Add(promotion_knight_w_2); board.chessman.Add(promotion_bishop_w_2); board.chessman.Add(promotion_rook_w_2); // SCHWARZE SPIELFIGUREN board.chessman.Add(promotion_pawn_b_1); board.chessman.Add(promotion_pawn_b_2); board.chessman.Add(promotion_king_b); board.chessman.Add(promotion_knight_b_2); board.chessman.Add(promotion_bishop_b_2); board.chessman.Add(promotion_rook_b_2); break; case "en_passant_setup": // WEISSE SPIELFIGUREN PawnWhite en_passant_pawn_w_1 = factory.GetPawnWhite("A2"); PawnWhite en_passant_pawn_w_2 = factory.GetPawnWhite("B2"); PawnWhite en_passant_pawn_w_3 = factory.GetPawnWhite("C4"); PawnWhite en_passant_pawn_w_4 = factory.GetPawnWhite("D2"); PawnWhite en_passant_pawn_w_5 = factory.GetPawnWhite("E2"); PawnWhite en_passant_pawn_w_6 = factory.GetPawnWhite("F2"); PawnWhite en_passant_pawn_w_7 = factory.GetPawnWhite("G2"); PawnWhite en_passant_pawn_w_8 = factory.GetPawnWhite("H2"); Rook en_passant_rook_w_1 = factory.GetRook("white", "A1"); Knight en_passant_knight_w_1 = factory.GetKnight("white", "B1"); Bishop en_passant_bishop_w_1 = factory.GetBishop("white", "C1"); Queen en_passant_queen_w = factory.GetQueen("white", "D1"); King en_passant_king_w = factory.GetKing("white", "E1"); Bishop en_passant_bishop_w_2 = factory.GetBishop("white", "F1"); Knight en_passant_knight_w_2 = factory.GetKnight("white", "G1"); Rook en_passant_rook_w_2 = factory.GetRook("white", "H1"); // SCHWARZE SPIELFIGUREN PawnBlack en_passant_pawn_b_1 = factory.GetPawnBlack("A7"); PawnBlack en_passant_pawn_b_2 = factory.GetPawnBlack("B7"); PawnBlack en_passant_pawn_b_3 = factory.GetPawnBlack("C7"); PawnBlack en_passant_pawn_b_4 = factory.GetPawnBlack("D7"); PawnBlack en_passant_pawn_b_5 = factory.GetPawnBlack("E7"); PawnBlack en_passant_pawn_b_6 = factory.GetPawnBlack("F5"); PawnBlack en_passant_pawn_b_7 = factory.GetPawnBlack("G7"); PawnBlack en_passant_pawn_b_8 = factory.GetPawnBlack("H7"); Rook en_passant_rook_b_1 = factory.GetRook("black", "A8"); Knight en_passant_knight_b_1 = factory.GetKnight("black", "B8"); Bishop en_passant_bishop_b_1 = factory.GetBishop("black", "C8"); Queen en_passant_queen_b = factory.GetQueen("black", "D8"); King en_passant_king_b = factory.GetKing("black", "E8"); Bishop en_passant_bishop_b_2 = factory.GetBishop("black", "F8"); Knight en_passant_knight_b_2 = factory.GetKnight("black", "G8"); Rook en_passant_rook_b_2 = factory.GetRook("black", "H8"); // WEISSE SPIELFIGUREN board.chessman.Add(en_passant_pawn_w_1); board.chessman.Add(en_passant_pawn_w_2); board.chessman.Add(en_passant_pawn_w_3); board.chessman.Add(en_passant_pawn_w_4); board.chessman.Add(en_passant_pawn_w_5); board.chessman.Add(en_passant_pawn_w_6); board.chessman.Add(en_passant_pawn_w_7); board.chessman.Add(en_passant_pawn_w_8); board.chessman.Add(en_passant_rook_w_1); board.chessman.Add(en_passant_rook_w_2); board.chessman.Add(en_passant_bishop_w_1); board.chessman.Add(en_passant_bishop_w_2); board.chessman.Add(en_passant_knight_w_1); board.chessman.Add(en_passant_knight_w_2); board.chessman.Add(en_passant_queen_w); board.chessman.Add(en_passant_king_w); // SCHWARZE SPIELFIGUREN board.chessman.Add(en_passant_pawn_b_1); board.chessman.Add(en_passant_pawn_b_2); board.chessman.Add(en_passant_pawn_b_3); board.chessman.Add(en_passant_pawn_b_4); board.chessman.Add(en_passant_pawn_b_5); board.chessman.Add(en_passant_pawn_b_6); board.chessman.Add(en_passant_pawn_b_7); board.chessman.Add(en_passant_pawn_b_8); board.chessman.Add(en_passant_rook_b_1); board.chessman.Add(en_passant_rook_b_2); board.chessman.Add(en_passant_bishop_b_1); board.chessman.Add(en_passant_bishop_b_2); board.chessman.Add(en_passant_knight_b_1); board.chessman.Add(en_passant_knight_b_2); board.chessman.Add(en_passant_queen_b); board.chessman.Add(en_passant_king_b); break; case "castling_setup": // WEISSE SPIELFIGUREN Rook castling_rook_w_1 = factory.GetRook("white", "A1"); King castling_king_w = factory.GetKing("white", "E1"); Rook castling_rook_w_2 = factory.GetRook("white", "H1"); // SCHWARZE SPIELFIGUREN Rook castling_rook_b_1 = factory.GetRook("black", "A8"); King castling_king_b = factory.GetKing("black", "E8"); Rook castling_rook_b_2 = factory.GetRook("black", "H8"); // WEISSE SPIELFIGUREN board.chessman.Add(castling_rook_w_1); board.chessman.Add(castling_rook_w_2); board.chessman.Add(castling_king_w); // SCHWARZE SPIELFIGUREN board.chessman.Add(castling_rook_b_1); board.chessman.Add(castling_rook_b_2); board.chessman.Add(castling_king_b); break; } }
/// <summary> /// Clear the board and place each piece on the board /// </summary> /// <param name="board"></param> public void placePieces(Board board) { board.clearBoard(board); //Instancing each piece Rook newBlackRook1 = new Rook("black", 0, 0); Knight newBlackKnight1 = new Knight("black", 0, 1); Bishop newBlackBishop1 = new Bishop("black", 0, 2); Queen newBlackQueen = new Queen("black", 0, 3); King newBlackKing = new King("black", 0, 4); Bishop newBlackBishop2 = new Bishop("black", 0, 5); Knight newBlackKnight2 = new Knight("black", 0, 6); Rook newBlackRook2 = new Rook("black", 0, 7); Pawn newBlackPawn1 = new Pawn("black", 1, 0); Pawn newBlackPawn2 = new Pawn("black", 1, 1); Pawn newBlackPawn3 = new Pawn("black", 1, 2); Pawn newBlackPawn4 = new Pawn("black", 1, 3); Pawn newBlackPawn5 = new Pawn("black", 1, 4); Pawn newBlackPawn6 = new Pawn("black", 1, 5); Pawn newBlackPawn7 = new Pawn("black", 1, 6); Pawn newBlackPawn8 = new Pawn("black", 1, 7); Rook newWhiteRook1 = new Rook("white", 7, 0); Knight newWhiteKnight1 = new Knight("white", 7, 1); Bishop newWhiteBishop1 = new Bishop("white", 7, 2); Queen newWhiteQueen = new Queen("white", 7, 3); King newWhiteKing = new King("white", 7, 4); Bishop newWhiteBishop2 = new Bishop("white", 7, 5); Knight newWhiteKnight2 = new Knight("white", 7, 6); Rook newWhiteRook2 = new Rook("white", 7, 7); Pawn newWhitePawn1 = new Pawn("white", 6, 0); Pawn newWhitePawn2 = new Pawn("white", 6, 1); Pawn newWhitePawn3 = new Pawn("white", 6, 2); Pawn newWhitePawn4 = new Pawn("white", 6, 3); Pawn newWhitePawn5 = new Pawn("white", 6, 4); Pawn newWhitePawn6 = new Pawn("white", 6, 5); Pawn newWhitePawn7 = new Pawn("white", 6, 6); Pawn newWhitePawn8 = new Pawn("white", 6, 7); //Placing each piece on the board board.Grid[0, 0, 0].WhoIsOnIt = newBlackRook1; board.Grid[0, 1, 0].WhoIsOnIt = newBlackKnight1; board.Grid[0, 2, 0].WhoIsOnIt = newBlackBishop1; board.Grid[0, 3, 0].WhoIsOnIt = newBlackQueen; board.Grid[0, 4, 0].WhoIsOnIt = newBlackKing; board.Grid[0, 5, 0].WhoIsOnIt = newBlackBishop2; board.Grid[0, 6, 0].WhoIsOnIt = newBlackKnight2; board.Grid[0, 7, 0].WhoIsOnIt = newBlackRook2; board.Grid[1, 0, 0].WhoIsOnIt = newBlackPawn1; board.Grid[1, 1, 0].WhoIsOnIt = newBlackPawn2; board.Grid[1, 2, 0].WhoIsOnIt = newBlackPawn3; board.Grid[1, 3, 0].WhoIsOnIt = newBlackPawn4; board.Grid[1, 4, 0].WhoIsOnIt = newBlackPawn5; board.Grid[1, 5, 0].WhoIsOnIt = newBlackPawn6; board.Grid[1, 6, 0].WhoIsOnIt = newBlackPawn7; board.Grid[1, 7, 0].WhoIsOnIt = newBlackPawn8; board.Grid[7, 0, 0].WhoIsOnIt = newWhiteRook1; board.Grid[7, 1, 0].WhoIsOnIt = newWhiteKnight1; board.Grid[7, 2, 0].WhoIsOnIt = newWhiteBishop1; board.Grid[7, 3, 0].WhoIsOnIt = newWhiteQueen; board.Grid[7, 4, 0].WhoIsOnIt = newWhiteKing; board.Grid[7, 5, 0].WhoIsOnIt = newWhiteBishop2; board.Grid[7, 6, 0].WhoIsOnIt = newWhiteKnight2; board.Grid[7, 7, 0].WhoIsOnIt = newWhiteRook2; board.Grid[6, 0, 0].WhoIsOnIt = newWhitePawn1; board.Grid[6, 1, 0].WhoIsOnIt = newWhitePawn2; board.Grid[6, 2, 0].WhoIsOnIt = newWhitePawn3; board.Grid[6, 3, 0].WhoIsOnIt = newWhitePawn4; board.Grid[6, 4, 0].WhoIsOnIt = newWhitePawn5; board.Grid[6, 5, 0].WhoIsOnIt = newWhitePawn6; board.Grid[6, 6, 0].WhoIsOnIt = newWhitePawn7; board.Grid[6, 7, 0].WhoIsOnIt = newWhitePawn8; }
internal static Piece[,] GetFairyDefault() { Piece[,] b = new Piece[BOARDSIZE, BOARDSIZE]; // Set Antelope for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)((seed % 2) * (BOARDSIZE - 1)); b[posX, (team * (BOARDSIZE - 1))] = new Antelope(team); } // Set Camel for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)((seed % 2) * (BOARDSIZE - 3) + 1); b[posX, (team * (BOARDSIZE - 1))] = new Camel(team); } // Set Bow for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)((seed % 2) * (BOARDSIZE - 5) + 2); b[posX, (team * (BOARDSIZE - 1))] = new Bow(team); } // Set Bull for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)((seed % 2) * (BOARDSIZE - 7) + 3); b[posX, (team * (BOARDSIZE - 1))] = new Bull(team); } // Set Cannon for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)((seed % 2) * (BOARDSIZE - 9) + 4); b[posX, (team * (BOARDSIZE - 1))] = new Cannon(team); } // Set Buffalo for (int seed = 0; seed < 2; seed++) { byte team = (byte)(seed % 2); b[5, (team * (BOARDSIZE - 1))] = new Buffalo(team); } // Set Rhinoceros for (int seed = 0; seed < 2; seed++) { byte team = (byte)(seed % 2); b[6, (team * (BOARDSIZE - 1))] = new Rhinoceros(team); } // Set Star for (int seed = 0; seed < 2; seed++) { byte team = (byte)(seed % 2); b[7, (team * (BOARDSIZE - 1))] = new Star(team); } // Set Unicorn for (int seed = 0; seed < 2; seed++) { byte team = (byte)(seed % 2); b[8, (team * (BOARDSIZE - 1))] = new Unicorn(team); } // Set DragonWoman for (int seed = 0; seed < 2; seed++) { byte team = (byte)(seed % 2); b[9, (team * (BOARDSIZE - 1))] = new DragonWoman(team); } // Set Diablo for (int seed = 0; seed < 2; seed++) { byte team = (byte)(seed % 2); b[10, (team * (BOARDSIZE - 1))] = new Diablo(team); } // Set Centurion for (int seed = 0; seed < 28; seed++) { byte team = (byte)((seed / 14) % 2); byte posX = (byte)(((9 + seed) + (team * 2)) % BOARDSIZE); b[posX, ((team * (BOARDSIZE - 3)) + 1)] = new Centurion(team); } // Set Lion for (int seed = 0; seed < 2; seed++) { byte team = (byte)(seed % 2); b[7, ((team * (BOARDSIZE - 3)) + 1)] = new Lion(team); } // Set Gryphon for (int seed = 0; seed < 2; seed++) { byte team = (byte)(seed % 2); b[8, ((team * (BOARDSIZE - 3)) + 1)] = new Gryphon(team); } // Set Elephant for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)((seed % 2) * (BOARDSIZE - 1)); b[posX, (team * (BOARDSIZE - 5)) + 2] = new Elephant(team); } // Set Machine for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)(((seed % 2) * (BOARDSIZE - 3)) + 1); b[posX, (team * (BOARDSIZE - 5)) + 2] = new Machine(team); } // Set Rook for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)(((seed % 2) * (BOARDSIZE - 5)) + 2); b[posX, (team * (BOARDSIZE - 5)) + 2] = new Rook(team); } // Set Knight for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)(((seed % 2) * (BOARDSIZE - 7)) + 3); b[posX, (team * (BOARDSIZE - 5)) + 2] = new Knight(team); } // Set Bishop for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)(((seed % 2) * (BOARDSIZE - 9)) + 4); b[posX, (team * (BOARDSIZE - 5)) + 2] = new Bishop(team); } // Set Ship for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)(((seed % 2) * (BOARDSIZE - 11)) + 5); b[posX, (team * (BOARDSIZE - 5)) + 2] = new Ship(team); } // Set Buffoon for (int seed = 0; seed < 4; seed++) { byte team = (byte)(seed / 2); byte posX = (byte)(((seed % 2) * (BOARDSIZE - 13)) + 6); b[posX, (team * (BOARDSIZE - 5)) + 2] = new Buffoon(team); } // Set Queen for (int seed = 0; seed < 2; seed++) { byte team = (byte)(seed % 2); b[7, ((team * (BOARDSIZE - 5)) + 2)] = new Queen(team); } // Set King for (int seed = 0; seed < 2; seed++) { byte team = (byte)(seed % 2); b[8, ((team * (BOARDSIZE - 5)) + 2)] = new King(team); } // Set FairyPawn for (int seed = 0; seed < 32; seed++) { byte team = (byte)(seed / 16); b[(seed % 16), (byte)((team * (BOARDSIZE - 7)) + 3)] = new FairyPawn(team); } return(b); }
private void InitializePlayersPieces() { foreach (var player in Players) { if (player.Pieces != null) { player.Pieces = null; } if (player.PlayerColor == Color.Black) { ChessPiece one = new Rook("R1", "R", player.PlayerColor, GetLocation("A1"), null, false) as ChessPiece; ChessPiece two = new Knight("Kn1", "Kn", player.PlayerColor, GetLocation("B1"), null, true) as ChessPiece; ChessPiece three = new Bishop("B1", "B", player.PlayerColor, GetLocation("C1"), null, false) as ChessPiece; //ChessPiece four = new ChessPiece("Q", "Q", player.PlayerColor, GetLocation("D1"), null); //ChessPiece five = new ChessPiece("K", "K", player.PlayerColor, GetLocation("E1"), null); ChessPiece six = new Bishop("B2", "B", player.PlayerColor, GetLocation("F1"), null, false) as ChessPiece; ChessPiece seven = new Knight("Kn2", "Kn", player.PlayerColor, GetLocation("G1"), null, true) as ChessPiece; ChessPiece eight = new Rook("R2", "R", player.PlayerColor, GetLocation("H1"), null, false) as ChessPiece; ChessPiece nine = new Pawn("P1", "P", player.PlayerColor, GetLocation("A2"), null, false) as ChessPiece; ChessPiece ten = new Pawn("P1", "P", player.PlayerColor, GetLocation("B2"), null, false) as ChessPiece; ChessPiece eleven = new Pawn("P1", "P", player.PlayerColor, GetLocation("C2"), null, false) as ChessPiece; ChessPiece twelve = new Pawn("P2", "P", player.PlayerColor, GetLocation("D2"), null, false) as ChessPiece; ChessPiece thirteen = new Pawn("P3", "P", player.PlayerColor, GetLocation("E2"), null, false) as ChessPiece; ChessPiece fourteen = new Pawn("P4", "P", player.PlayerColor, GetLocation("F2"), null, false) as ChessPiece; ChessPiece fifteen = new Pawn("P5", "P", player.PlayerColor, GetLocation("G2"), null, false) as ChessPiece; ChessPiece sixteen = new Pawn("P6", "P", player.PlayerColor, GetLocation("H2"), null, false) as ChessPiece; player.Pieces = new List <ChessPiece>(); player.Pieces.Add(one); player.Pieces.Add(two); player.Pieces.Add(three); //player.Pieces.Add(four); //player.Pieces.Add(five); player.Pieces.Add(six); player.Pieces.Add(seven); player.Pieces.Add(eight); player.Pieces.Add(nine); player.Pieces.Add(ten); player.Pieces.Add(eleven); player.Pieces.Add(twelve); player.Pieces.Add(thirteen); player.Pieces.Add(fourteen); player.Pieces.Add(fifteen); player.Pieces.Add(sixteen); } else { ChessPiece one = new Rook("R3", "R", player.PlayerColor, GetLocation("A8"), null, false) as ChessPiece; ChessPiece two = new Knight("Kn3", "Kn", player.PlayerColor, GetLocation("B8"), null, true) as ChessPiece; ChessPiece three = new Bishop("B3", "B", player.PlayerColor, GetLocation("C8"), null, false) as ChessPiece; //ChessPiece four = new ChessPiece("Q", "Q", player.PlayerColor, GetLocation("D8"), null); //ChessPiece five = new ChessPiece("K", "K", player.PlayerColor, GetLocation("E8"), null); ChessPiece six = new Bishop("B4", "B", player.PlayerColor, GetLocation("F8"), null, false) as ChessPiece; ChessPiece seven = new Knight("Kn4", "Kn", player.PlayerColor, GetLocation("G8"), null, true) as ChessPiece; ChessPiece eight = new Rook("R4", "R", player.PlayerColor, GetLocation("H8"), null, false) as ChessPiece; ChessPiece nine = new Pawn("P7", "P", player.PlayerColor, GetLocation("A7"), null, false) as ChessPiece; ChessPiece ten = new Pawn("P8", "P", player.PlayerColor, GetLocation("B7"), null, false) as ChessPiece; ChessPiece eleven = new Pawn("P9", "P", player.PlayerColor, GetLocation("C7"), null, false) as ChessPiece; ChessPiece twelve = new Pawn("P10", "P", player.PlayerColor, GetLocation("D7"), null, false) as ChessPiece; ChessPiece thirteen = new Pawn("P11", "P", player.PlayerColor, GetLocation("E7"), null, false) as ChessPiece; ChessPiece fourteen = new Pawn("P12", "P", player.PlayerColor, GetLocation("F7"), null, false) as ChessPiece; ChessPiece fifteen = new Pawn("P13", "P", player.PlayerColor, GetLocation("G7"), null, false) as ChessPiece; ChessPiece sixteen = new Pawn("P14", "P", player.PlayerColor, GetLocation("H7"), null, false) as ChessPiece; player.Pieces = new List <ChessPiece>(); player.Pieces.Add(one); player.Pieces.Add(two); player.Pieces.Add(three); //player.Pieces.Add(four); //player.Pieces.Add(five); player.Pieces.Add(six); player.Pieces.Add(seven); player.Pieces.Add(eight); player.Pieces.Add(nine); player.Pieces.Add(ten); player.Pieces.Add(eleven); player.Pieces.Add(twelve); player.Pieces.Add(thirteen); player.Pieces.Add(fourteen); player.Pieces.Add(fifteen); player.Pieces.Add(sixteen); } } }
public GameBoard() { King BlackKing = new King("BLACK"); Queen BlackQueen = new Queen("BLACK", 1); Castle BlackCastle1 = new Castle("BLACK", 1); Castle BlackCastle2 = new Castle("BLACK", 2); Bishop BlackBishop1 = new Bishop("BLACK", 1); Bishop BlackBishop2 = new Bishop("BLACK", 2); Knight BlackKnight1 = new Knight("BLACK", 1); Knight BlackKnight2 = new Knight("BLACK", 2); Pawn BlackPawn1 = new Pawn("BLACK", 1); Pawn BlackPawn2 = new Pawn("BLACK", 2); Pawn BlackPawn3 = new Pawn("BLACK", 3); Pawn BlackPawn4 = new Pawn("BLACK", 4); Pawn BlackPawn5 = new Pawn("BLACK", 5); Pawn BlackPawn6 = new Pawn("BLACK", 6); Pawn BlackPawn7 = new Pawn("BLACK", 7); Pawn BlackPawn8 = new Pawn("BLACK", 8); Empty Emptyspace = new Empty(); for (byte i = 2; i < 6; i++) { for (byte j = 0; j < 8; j++) { Chessboard[i, j] = Emptyspace; } } Black.Add(BlackKing); Black.Add(BlackQueen); Black.Add(BlackCastle1); Black.Add(BlackCastle2); Black.Add(BlackBishop1); Black.Add(BlackBishop2); Black.Add(BlackKnight1); Black.Add(BlackKnight2); Black.Add(BlackPawn1); Black.Add(BlackPawn2); Black.Add(BlackPawn3); Black.Add(BlackPawn4); Black.Add(BlackPawn5); Black.Add(BlackPawn6); Black.Add(BlackPawn7); Black.Add(BlackPawn8); King WhiteKing = new King("WHITE"); Queen WhiteQueen = new Queen("WHITE", 1); Castle WhiteCastle1 = new Castle("WHITE", 1); Castle WhiteCastle2 = new Castle("WHITE", 2); Bishop WhiteBishop1 = new Bishop("WHITE", 1); Bishop WhiteBishop2 = new Bishop("WHITE", 2); Knight WhiteKnight1 = new Knight("WHITE", 1); Knight WhiteKnight2 = new Knight("WHITE", 2); Pawn WhitePawn1 = new Pawn("WHITE", 1); Pawn WhitePawn2 = new Pawn("WHITE", 2); Pawn WhitePawn3 = new Pawn("WHITE", 3); Pawn WhitePawn4 = new Pawn("WHITE", 4); Pawn WhitePawn5 = new Pawn("WHITE", 5); Pawn WhitePawn6 = new Pawn("WHITE", 6); Pawn WhitePawn7 = new Pawn("WHITE", 7); Pawn WhitePawn8 = new Pawn("WHITE", 8); White.Add(WhiteKing); White.Add(WhiteQueen); White.Add(WhiteCastle1); White.Add(WhiteCastle2); White.Add(WhiteBishop1); White.Add(WhiteBishop2); White.Add(WhiteKnight1); White.Add(WhiteKnight2); White.Add(WhitePawn1); White.Add(WhitePawn2); White.Add(WhitePawn3); White.Add(WhitePawn4); White.Add(WhitePawn5); White.Add(WhitePawn6); White.Add(WhitePawn7); White.Add(WhitePawn8); Chessboard[0, 0] = WhiteCastle1; Chessboard[0, 1] = WhiteKnight1; Chessboard[0, 2] = WhiteBishop1; Chessboard[0, 3] = WhiteQueen; Chessboard[0, 4] = WhiteKing; Chessboard[0, 5] = WhiteBishop2; Chessboard[0, 6] = WhiteKnight2; Chessboard[0, 7] = WhiteCastle2; Chessboard[1, 0] = WhitePawn1; Chessboard[1, 1] = WhitePawn2; Chessboard[1, 2] = WhitePawn3; Chessboard[1, 3] = WhitePawn4; Chessboard[1, 4] = WhitePawn5; Chessboard[1, 5] = WhitePawn6; Chessboard[1, 6] = WhitePawn7; Chessboard[1, 7] = WhitePawn8; Chessboard[7, 0] = BlackCastle1; Chessboard[7, 1] = BlackKnight1; Chessboard[7, 2] = BlackBishop1; Chessboard[7, 3] = BlackQueen; Chessboard[7, 4] = BlackKing; Chessboard[7, 5] = BlackBishop2; Chessboard[7, 6] = BlackKnight2; Chessboard[7, 7] = BlackCastle2; Chessboard[6, 0] = BlackPawn1; Chessboard[6, 1] = BlackPawn2; Chessboard[6, 2] = BlackPawn3; Chessboard[6, 3] = BlackPawn4; Chessboard[6, 4] = BlackPawn5; Chessboard[6, 5] = BlackPawn6; Chessboard[6, 6] = BlackPawn7; Chessboard[6, 7] = BlackPawn8; for (byte i = 0; i < 8; i++) { for (byte j = 0; j < 8; j++) { if (!(Chessboard[i, j].GetType().ToString().Contains("Empty"))) { Chessboard[i, j].Current.X = i; Chessboard[i, j].Current.Y = j; } } } }
public bool ChecktestWhite(GameBoard _Game) { int i; King Kingmover1 = new King("White"); for (i = 0; i < _Game.White.Count; i++) { if (_Game.White[i].GetType().ToString().Contains("King")) { Kingmover1 = (King)_Game.White[i]; break; } } Coordinate _Next = Kingmover1.Current; string typecheck; for (i = 0; i < _Game.Black.Count; i++) { typecheck = _Game.Black[i].GetType().ToString(); if (_Game.Black[i].Current.X == 99) { continue; } switch (typecheck) { case "Chess.Pawn": Pawn Pawnmover = new Pawn("a"); Pawnmover = (Pawn)_Game.Black[i]; if (Pawnmover.isMovable(_Game, _Next)) { return(true); } break; case "Chess.Bishop": Bishop Bishopmover = new Bishop("a"); Bishopmover = (Bishop)_Game.Black[i]; if (Bishopmover.isMovable(_Game, _Next)) { return(true); } break; case "Chess.Queen": Queen Queenmover = new Queen("a"); Queenmover = (Queen)_Game.Black[i]; if (Queenmover.isMovable(_Game, _Next)) { return(true); } break; case "Chess.Knight": Knight Knightmover = new Knight("a"); Knightmover = (Knight)_Game.Black[i]; if (Knightmover.isMovable(_Game, _Next)) { return(true); } break; case "Chess.Castle": Castle Castlemover = new Castle("a"); Castlemover = (Castle)_Game.Black[i]; if (Castlemover.isMovable(_Game, _Next)) { return(true); } break; case "Chess.King": King Kingmover2 = new King("a"); Kingmover2 = (King)_Game.Black[i]; if (Kingmover2.isMovable(_Game, _Next)) { return(true); } break; } } return(false); }
public void initBoard() { Console.WriteLine("INIT Board"); /* Queens */ chessPiece QueenW = new Queen(false, 7, 3); chessBoard[QueenW.getX(), QueenW.getY()] = QueenW; chessPiece QueenB = new Queen(true, 0, 3); chessBoard[QueenB.getX(), QueenB.getY()] = QueenB; // /* Kings */ chessPiece KingW = new King(false, 7, 4); chessBoard[KingW.getX(), KingW.getY()] = KingW; setKingLocation(false, 7, 4); chessPiece KingB = new King(true, 0, 4); chessBoard[KingB.getX(), KingB.getY()] = KingB; setKingLocation(true, 0, 4); // /* Bishops */ chessPiece BishW1 = new Bishop(false, 7, 2); chessBoard[BishW1.getX(), BishW1.getY()] = BishW1; chessPiece BishW2 = new Bishop(false, 7, 5); chessBoard[BishW2.getX(), BishW2.getY()] = BishW2; // Blacks chessPiece BishB1 = new Bishop(true, 0, 2); chessBoard[BishB1.getX(), BishB1.getY()] = BishB1; chessPiece BishB2 = new Bishop(true, 0, 5); chessBoard[BishB2.getX(), BishB2.getY()] = BishB2; // /* Knights */ chessPiece KnW1 = new Knight(false, 7, 1); chessBoard[KnW1.getX(), KnW1.getY()] = KnW1; chessPiece KnW2 = new Knight(false, 7, 6); chessBoard[KnW2.getX(), KnW2.getY()] = KnW2; // Blacks chessPiece KnB1 = new Knight(true, 0, 1); chessBoard[KnB1.getX(), KnB1.getY()] = KnB1; chessPiece KnB2 = new Knight(true, 0, 6); chessBoard[KnB2.getX(), KnB2.getY()] = KnB2; /* Rooks */ chessPiece RookW1 = new Rook(false, 7, 0); chessBoard[RookW1.getX(), RookW1.getY()] = RookW1; chessPiece RookW2 = new Rook(false, 7, 7); chessBoard[RookW2.getX(), RookW2.getY()] = RookW2; // Blacks chessPiece RookB1 = new Rook(true, 0, 0); chessBoard[RookB1.getX(), RookB1.getY()] = RookB1; chessPiece RookB2 = new Rook(true, 0, 7); chessBoard[RookB2.getX(), RookB2.getY()] = RookB2; /* Pawns */ // chessPiece PawnW1 = new Pawn(false, 4, 4); // chessBoard[PawnW1.getX(), PawnW1.getY()] = PawnW1; // chessPiece PawnW2 = new Pawn(false, 6, 1); // chessBoard[PawnW2.getX(), PawnW2.getY()] = PawnW2; // chessPiece PawnW3 = new Pawn(false, 6, 2); // chessBoard[PawnW3.getX(), PawnW3.getY()] = PawnW3; // chessPiece PawnW4 = new Pawn(false, 6, 3); // chessBoard[PawnW4.getX(), PawnW4.getY()] = PawnW4; // chessPiece PawnW5 = new Pawn(false, 6, 4); // chessBoard[PawnW5.getX(), PawnW5.getY()] = PawnW5; // chessPiece PawnW6 = new Pawn(false, 6, 5); // chessBoard[PawnW6.getX(), PawnW6.getY()] = PawnW6; // chessPiece PawnW7 = new Pawn(false, 6, 6); // chessBoard[PawnW7.getX(), PawnW7.getY()] = PawnW7; // chessPiece PawnW8 = new Pawn(false, 6, 7); // chessBoard[PawnW8.getX(), PawnW8.getY()] = PawnW8; // // Blacks // chessPiece PawnB1 = new Pawn(true, 1, 0); // chessBoard[PawnB1.getX(), PawnB1.getY()] = PawnB1; // chessPiece PawnB2 = new Pawn(true, 1, 1); // chessBoard[PawnB2.getX(), PawnB2.getY()] = PawnB2; // chessPiece PawnB3 = new Pawn(true, 1, 2); // chessBoard[PawnB3.getX(), PawnB3.getY()] = PawnB3; // chessPiece PawnB4 = new Pawn(true, 1, 3); // chessBoard[PawnB4.getX(), PawnB4.getY()] = PawnB4; // chessPiece PawnB5 = new Pawn(true, 1, 4); // chessBoard[PawnB5.getX(), PawnB5.getY()] = PawnB5; // chessPiece PawnB6 = new Pawn(true, 1, 5); // chessBoard[PawnB6.getX(), PawnB6.getY()] = PawnB6; // chessPiece PawnB7 = new Pawn(true, 1, 6); // chessBoard[PawnB7.getX(), PawnB7.getY()] = PawnB7; // chessPiece PawnB8 = new Pawn(true, 1, 7); // chessBoard[PawnB8.getX(), PawnB8.getY()] = PawnB8; }
static List <IPiece> readPieces() { String input; List <IPiece> pieces = new List <IPiece>(); int numberPieces = -1; while (numberPieces < 0) { Console.Write("Enter number of pieces: "); input = Console.ReadLine(); if (!Int32.TryParse(input, out numberPieces)) { numberPieces = -1; } } Console.WriteLine(); int i; for (i = 1; i <= numberPieces; i++) { IPiece piece; Console.WriteLine("Piece {0}", i); input = ""; while ((!input.StartsWith("W")) && (!input.StartsWith("B"))) { Console.Write("Enter colour (W/B): "); input = Console.ReadLine(); } PieceColour colour; if (input == "B") { colour = PieceColour.BLACK; } else { colour = PieceColour.WHITE; } input = ""; while ((!input.StartsWith("B")) && (!input.StartsWith("N"))) { Console.Write("Enter type (B/N): "); input = Console.ReadLine(); } String pieceType = input; input = ""; Position p; while (!Position.tryParse(input, out p)) { Console.Write("Enter position: "); input = Console.ReadLine(); } if (pieceType.StartsWith("N")) { piece = new Knight(colour, p); } else { piece = new Bishop(colour, p); } Console.WriteLine(); pieces.Add(piece); } return(pieces); }
public void MakePlay(Position origin, Position destination) { Piece capturedPiece = ExecuteMoviment(origin, destination); if (IsInCheck(ActualPlayer)) { RemakePlay(origin, destination, capturedPiece); throw new BoardException("You can't put yourself in check"); } Piece p = Board.Piece(destination); //#Promotion if (p is Pawn) { if (p.Color == Colors.White && destination.Line == 0 || p.Color == Colors.Black && destination.Line == 7) { p = Board.RemovePiece(destination); _pieces.Remove(p); Console.Write("Promotion: ('Q'|'K'|'B'|'R')"); char promotion = char.Parse(Console.ReadLine()); switch (promotion) { case 'q': p = new Queen(p.Color, Board); break; case 'k': p = new Knight(p.Color, Board); break; case 'b': p = new Bishop(ActualPlayer, Board); break; case 'r': p = new Rook(ActualPlayer, Board); break; default: p = new Queen(ActualPlayer, Board); break; } Board.PutPiece(p, destination); _pieces.Add(p); } } if (IsInCheck(Adversary(ActualPlayer))) { Check = true; } else { Check = false; } if (CheckMate(Adversary(ActualPlayer))) { Ended = true; } else { Turn++; SwitchPlayer(); } //#EnPassant if (p is Pawn && (destination.Line == origin.Line + 2) || (destination.Line == origin.Line - 2)) { VulnerableEnPassant = p; } else { VulnerableEnPassant = null; } }
public void KnightShouldBeCorrectMove() { ChessFigure figure = new Knight("B1"); Assert.AreEqual(true, figure.Move("C3")); }
static void Main(string[] args) { Position pawn1StartingPosition = new Position(0, 1); Pawn pawn1 = new Pawn(pawn1StartingPosition); Position[] pawn1MovementOptions = pawn1.MovementOptions(); Console.WriteLine("A posição inicial do Peão 1 é:"); pawn1.Pos.Print(); Console.WriteLine("A posição válida para movimento dele é:"); pawn1MovementOptions[0].Print(); Console.WriteLine(); Position rook1StartingPosition = new Position(0, 0); Rook rook1 = new Rook(rook1StartingPosition); Position[] rook1MovementOptions = rook1.MovementOptions(); Console.WriteLine("A posição inicial da Torre 1 é:"); rook1.Pos.Print(); Console.WriteLine("As posições válidas para movimento dele são:"); for (int i = 0; i < rook1.MovementOptions().Length; i++) { rook1MovementOptions[i].Print(); } Position bishop1StartingPosition = new Position(2, 0); Bishop bishop1 = new Bishop(bishop1StartingPosition); Position[] bishop1MovementOptions = bishop1.MovementOptions(); Console.WriteLine("A posição inicial do Bispo 1 é:"); bishop1.Pos.Print(); Console.WriteLine("As posições válidas para movimento dele são:"); for (int i = 0; i < bishop1.MovementOptions().Length; i++) { bishop1MovementOptions[i].Print(); } Position knight1StartingPosition = new Position(1, 0); Knight knight1 = new Knight(knight1StartingPosition); Position[] knight1MovementOptions = knight1.MovementOptions(); Console.WriteLine("A posição inicial do Cavaleiro 1 é:"); knight1.Pos.Print(); Console.WriteLine("As posições válidas para movimento dele são:"); for (int i = 0; i < knight1.MovementOptions().Length; i++) { knight1MovementOptions[i].Print(); } Position queen1StartingPosition = new Position(4, 0); Queen queen1 = new Queen(queen1StartingPosition); Position[] queen1MovementOptions = queen1.MovementOptions(); Console.WriteLine("A posição inicial da Rainha 1 é:"); queen1.Pos.Print(); Console.WriteLine("As posições válidas para movimento dela são:"); for (int i = 0; i < queen1.MovementOptions().Length; i++) { queen1MovementOptions[i].Print(); } Position king1StartingPosition = new Position(3, 0); King king1 = new King(king1StartingPosition); Position[] king1MovementOptions = king1.MovementOptions(); Console.WriteLine("A posição inicial do Rei 1 é:"); king1.Pos.Print(); Console.WriteLine("As posições válidas para movimento dele são:"); for (int i = 0; i < king1.MovementOptions().Length; i++) { king1MovementOptions[i].Print(); } Console.ReadKey(); }
public static void AddPiece(this Game game, Square square, PieceType type) { Piece piece = null; switch (type) { case PieceType.NoPiece: break; case PieceType.WhiteKing: piece = new King(Color.White); break; case PieceType.WhiteQueen: piece = new Queen(Color.White); break; case PieceType.WhiteRook: piece = new Rook(Color.White); break; case PieceType.WhiteBishop: piece = new Bishop(Color.White); break; case PieceType.WhiteNight: piece = new Knight(Color.White); break; case PieceType.WhitePawn: piece = new Pawn(Color.White); break; case PieceType.BlackKing: piece = new King(Color.Black); break; case PieceType.BlackQueen: piece = new Queen(Color.Black); break; case PieceType.BlackRook: piece = new Rook(Color.Black); break; case PieceType.BlackBishop: piece = new Bishop(Color.Black); break; case PieceType.BlackKnight: piece = new Knight(Color.Black); break; case PieceType.BlackPawn: piece = new Pawn(Color.Black); break; default: throw new NotImplementedException(); } game.AddPiece(square.File, square.Rank, piece); }
public static void SetupBoard() { Pawn p1W = new Pawn(0, 6, "WHITE"); Pawn p2W = new Pawn(1, 6, "WHITE"); Pawn p3W = new Pawn(2, 6, "WHITE"); Pawn p4W = new Pawn(3, 6, "WHITE"); Pawn p5W = new Pawn(4, 6, "WHITE"); Pawn p6W = new Pawn(5, 6, "WHITE"); Pawn p7W = new Pawn(6, 6, "WHITE"); Pawn p8W = new Pawn(7, 6, "WHITE"); Rook r1W = new Rook(0, 7, "WHITE"); Knight n1W = new Knight(1, 7, "WHITE"); Bishop b1W = new Bishop(2, 7, "WHITE"); Queen q1W = new Queen(3, 7, "WHITE"); King k1W = new King(4, 7, "WHITE"); Bishop b2W = new Bishop(5, 7, "WHITE"); Knight n2W = new Knight(6, 7, "WHITE"); Rook r2W = new Rook(7, 7, "WHITE"); Pawn p1B = new Pawn(0, 1, "BLACK"); Pawn p2B = new Pawn(1, 1, "BLACK"); Pawn p3B = new Pawn(2, 1, "BLACK"); Pawn p4B = new Pawn(3, 1, "BLACK"); Pawn p5B = new Pawn(4, 1, "BLACK"); Pawn p6B = new Pawn(5, 1, "BLACK"); Pawn p7B = new Pawn(6, 1, "BLACK"); Pawn p8B = new Pawn(7, 1, "BLACK"); Rook r1B = new Rook(0, 0, "BLACK"); Knight n1B = new Knight(1, 0, "BLACK"); Bishop b1B = new Bishop(2, 0, "BLACK"); Queen q1B = new Queen(3, 0, "BLACK"); King k1B = new King(4, 0, "BLACK"); Bishop b2B = new Bishop(5, 0, "BLACK"); Knight n2B = new Knight(6, 0, "BLACK"); Rook r2B = new Rook(7, 0, "BLACK"); board[p1W.Y, p1W.X] = p1W; board[p2W.Y, p2W.X] = p2W; board[p3W.Y, p3W.X] = p3W; board[p4W.Y, p4W.X] = p4W; board[p5W.Y, p5W.X] = p5W; board[p6W.Y, p6W.X] = p6W; board[p7W.Y, p7W.X] = p7W; board[p8W.Y, p8W.X] = p8W; board[r1W.Y, r1W.X] = r1W; board[n1W.Y, n1W.X] = n1W; board[b1W.Y, b1W.X] = b1W; board[q1W.Y, q1W.X] = q1W; board[k1W.Y, k1W.X] = k1W; board[b2W.Y, b2W.X] = b2W; board[n2W.Y, n2W.X] = n2W; board[r2W.Y, r2W.X] = r2W; board[p1B.Y, p1B.X] = p1B; board[p2B.Y, p2B.X] = p2B; board[p3B.Y, p3B.X] = p3B; board[p4B.Y, p4B.X] = p4B; board[p5B.Y, p5B.X] = p5B; board[p6B.Y, p6B.X] = p6B; board[p7B.Y, p7B.X] = p7B; board[p8B.Y, p8B.X] = p8B; board[r1B.Y, r1B.X] = r1B; board[n1B.Y, n1B.X] = n1B; board[b1B.Y, b1B.X] = b1B; board[q1B.Y, q1B.X] = q1B; board[k1B.Y, k1B.X] = k1B; board[b2B.Y, b2B.X] = b2B; board[n2B.Y, n2B.X] = n2B; board[r2B.Y, r2B.X] = r2B; }
public void Initialize() { //Initialize all squares for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { Square square = new Square(); square.File = (File)(i); square.Rank = j; BoardCoordinates.Add(square); } } //Initialize all pieces int whiteMajorPieceRank = 1; int whitePawnRank = 2; int blackPawnRank = 7; int blackMajorPieceRank = 8; File queenRookFile = File.A; File queenKnightFile = File.B; File queenBishopFile = File.C; File queenFile = File.D; File kingFile = File.E; File kingBishopFile = File.F; File kingKnightFile = File.G; File kingRookFile = File.H; #region Pawns for (int i = 0; i < 16; i++) { Pawn pawn = new Pawn(); pawn.PieceColor = i < 8 ? PieceColor.White : PieceColor.Black; pawn.Coordinates.Rank = i < 8 ? whitePawnRank : blackPawnRank; pawn.Coordinates.File = (File)(i % 8); pawn.IsOnBoard = true; Pieces.Add(pawn); } #endregion #region Rooks Rook whiteKingRook = new Rook(); whiteKingRook.Coordinates.Rank = whiteMajorPieceRank; whiteKingRook.Coordinates.File = kingRookFile; whiteKingRook.IsOnBoard = true; whiteKingRook.PieceColor = PieceColor.White; Pieces.Add(whiteKingRook); Rook whiteQueenRook = new Rook(); whiteQueenRook.Coordinates.Rank = whiteMajorPieceRank; whiteQueenRook.Coordinates.File = queenRookFile; whiteQueenRook.IsOnBoard = true; whiteQueenRook.PieceColor = PieceColor.White; Pieces.Add(whiteQueenRook); Rook blackKingRook = new Rook(); blackKingRook.Coordinates.Rank = blackMajorPieceRank; blackKingRook.Coordinates.File = kingRookFile; blackKingRook.IsOnBoard = true; blackKingRook.PieceColor = PieceColor.Black; Pieces.Add(blackKingRook); Rook blackQueenRook = new Rook(); blackQueenRook.Coordinates.File = queenRookFile; blackQueenRook.Coordinates.Rank = blackMajorPieceRank; blackQueenRook.IsOnBoard = true; blackQueenRook.PieceColor = PieceColor.Black; Pieces.Add(blackQueenRook); #endregion #region Knights Knight whiteQueenKnight = new Knight(); whiteQueenKnight.Coordinates.File = queenKnightFile; whiteQueenKnight.Coordinates.Rank = whiteMajorPieceRank; whiteQueenKnight.IsOnBoard = true; whiteQueenKnight.PieceColor = PieceColor.White; Pieces.Add(whiteQueenKnight); Knight whiteKingKnight = new Knight(); whiteKingKnight.Coordinates.File = kingKnightFile; whiteKingKnight.Coordinates.Rank = whiteMajorPieceRank; whiteKingKnight.IsOnBoard = true; whiteKingKnight.PieceColor = PieceColor.White; Pieces.Add(whiteKingKnight); Knight blackQueenKnight = new Knight(); blackQueenKnight.Coordinates.File = queenKnightFile; blackQueenKnight.Coordinates.Rank = blackMajorPieceRank; blackQueenKnight.IsOnBoard = true; blackQueenKnight.PieceColor = PieceColor.Black; Pieces.Add(blackQueenKnight); Knight blackKingKnight = new Knight(); blackKingKnight.Coordinates.File = kingKnightFile; blackKingKnight.Coordinates.Rank = blackMajorPieceRank; blackQueenKnight.IsOnBoard = true; blackQueenKnight.PieceColor = PieceColor.Black; Pieces.Add(blackKingKnight); #endregion #region Bishop Bishop whiteKingBishop = new Bishop(); whiteKingBishop.Coordinates.Rank = whiteMajorPieceRank; whiteKingBishop.Coordinates.File = kingBishopFile; whiteKingBishop.IsOnBoard = true; whiteKingBishop.PieceColor = PieceColor.White; Pieces.Add(whiteKingBishop); Bishop whiteQueenBishop = new Bishop(); whiteQueenBishop.Coordinates.Rank = whiteMajorPieceRank; whiteQueenBishop.Coordinates.File = queenBishopFile; whiteQueenBishop.IsOnBoard = true; whiteQueenBishop.PieceColor = PieceColor.White; Pieces.Add(whiteQueenBishop); Bishop blackKingBishop = new Bishop(); blackKingBishop.Coordinates.Rank = blackMajorPieceRank; blackKingBishop.Coordinates.File = kingBishopFile; blackKingBishop.IsOnBoard = true; blackKingBishop.PieceColor = PieceColor.Black; Pieces.Add(blackKingBishop); Bishop blackQueenBishop = new Bishop(); blackQueenBishop.Coordinates.Rank = blackMajorPieceRank; blackQueenBishop.Coordinates.File = queenBishopFile; blackQueenBishop.IsOnBoard = true; blackQueenBishop.PieceColor = PieceColor.Black; Pieces.Add(blackQueenBishop); #endregion #region Queens Queen whiteQueen = new Queen(); whiteQueen.Coordinates.Rank = whiteMajorPieceRank; whiteQueen.Coordinates.File = queenFile; whiteQueen.IsOnBoard = true; whiteQueen.PieceColor = PieceColor.White; Pieces.Add(whiteQueen); Queen blackQueen = new Queen(); blackQueen.Coordinates.Rank = blackMajorPieceRank; blackQueen.Coordinates.File = queenFile; blackQueen.IsOnBoard = true; blackQueen.PieceColor = PieceColor.Black; Pieces.Add(blackQueen); #endregion #region Kings King whiteKing = new King(); whiteKing.Coordinates.Rank = whiteMajorPieceRank; whiteKing.Coordinates.File = kingFile; whiteKing.IsOnBoard = true; whiteKing.PieceColor = PieceColor.White; Pieces.Add(whiteKing); King blackKing = new King(); blackKing.Coordinates.File = kingFile; blackKing.Coordinates.Rank = blackMajorPieceRank; blackKing.IsOnBoard = true; blackKing.PieceColor = PieceColor.Black; Pieces.Add(blackKing); #endregion }
/********************************************************************* * SetPieces * Set up all of the pieces on the board *********************************************************************/ void SetPieces() { Pawn w; Pawn b; for (int i = 0; i < 8; i++) { w = new Pawn("white"); board[i, 1].SetPiece(w); whiteTeam.Add(w); b = new Pawn("black"); board[i, 6].SetPiece(b); blackTeam.Add(b); } Rook rook = new Rook("white"); board[0, 0].SetPiece(rook); whiteTeam.Add(rook); rook = new Rook("white"); board[7, 0].SetPiece(rook); whiteTeam.Add(rook); Rook rookB = new Rook("black"); board[0, 7].SetPiece(rookB); blackTeam.Add(rookB); rookB = new Rook("black"); board[7, 7].SetPiece(rookB); blackTeam.Add(rookB); Knight knight = new Knight("white"); board[1, 0].SetPiece(knight); whiteTeam.Add(knight); knight = new Knight("white"); board[6, 0].SetPiece(knight); whiteTeam.Add(knight); Knight knightB = new Knight("black"); board[1, 7].SetPiece(knightB); blackTeam.Add(knightB); knightB = new Knight("black"); board[6, 7].SetPiece(knightB); blackTeam.Add(knightB); Bishop bishop = new Bishop("white"); board[2, 0].SetPiece(bishop); whiteTeam.Add(bishop); bishop = new Bishop("white"); board[5, 0].SetPiece(bishop); whiteTeam.Add(bishop); Bishop bishopB = new Bishop("black"); board[2, 7].SetPiece(bishopB); blackTeam.Add(bishopB); bishopB = new Bishop("black"); board[5, 7].SetPiece(bishopB); blackTeam.Add(bishopB); Queen queen = new Queen("white"); board[3, 0].SetPiece(queen); whiteTeam.Add(queen); queen = new Queen("black"); board[3, 7].SetPiece(queen); blackTeam.Add(queen); King king = new King("white"); board[4, 0].SetPiece(king); whiteTeam.Add(king); king = new King("black"); board[4, 7].SetPiece(king); blackTeam.Add(king); }