private void Start() { for (int i = 0; i < 8; i++) { keyValuePairs[i, 1] = new Pawn(pawnW, new Vector2(i, 1), FigColor.White); keyValuePairs[i, 6] = new Pawn(pawnB, new Vector2(i, 6), FigColor.Black); } for (int i = 0; i < 2; i++) { int iMul7 = i * 7; keyValuePairs[iMul7, 0] = new Rook(rookW, new Vector2(iMul7, 0), FigColor.White); keyValuePairs[iMul7, 7] = new Rook(rookB, new Vector2(iMul7, 7), FigColor.Black); iMul7 = i * 5 + 1; keyValuePairs[iMul7, 0] = new Knight(knightW, new Vector2(iMul7, 0), FigColor.White); keyValuePairs[iMul7, 7] = new Knight(knightB, new Vector2(iMul7, 7), FigColor.Black); iMul7 = i * 3 + 2; keyValuePairs[iMul7, 0] = new Bishop(bishopW, new Vector2(iMul7, 0), FigColor.White); keyValuePairs[iMul7, 7] = new Bishop(bishopB, new Vector2(iMul7, 7), FigColor.Black); } keyValuePairs[3, 0] = new Queen(queenW, new Vector2(3, 0), FigColor.White); keyValuePairs[3, 7] = new Queen(queenB, new Vector2(3, 7), FigColor.Black); keyValuePairs[4, 0] = new King(kingW, new Vector2(4, 0), FigColor.White); whiteKing = keyValuePairs[4, 0] as King; keyValuePairs[4, 7] = new King(kingB, new Vector2(4, 7), FigColor.Black); blackKing = keyValuePairs[4, 7] as King; }
public static Piece[] GenerateBlack() { Piece[] pieces = new Piece[16]; Piece[] pawns = GeneratePawns(GameColor.Black); pieces[0] = new Castle(1, new Vector2(0), new Vector2(0), ResourceManager.Instance.Textures[GameColor.Black.ToString().ToLower() + "_castle"], GameColor.Black); pieces[1] = new Knight(2, new Vector2(1, 0), new Vector2(64, 0), ResourceManager.Instance.Textures[GameColor.Black.ToString().ToLower() + "_knight"], GameColor.Black); pieces[2] = new Bishop(3, new Vector2(2, 0), new Vector2(128, 0), ResourceManager.Instance.Textures[GameColor.Black.ToString().ToLower() + "_bishop"], GameColor.Black); pieces[3] = new King(4, new Vector2(3, 0), new Vector2(64 * 3, 0), ResourceManager.Instance.Textures[GameColor.Black.ToString().ToLower() + "_king"], GameColor.Black); pieces[4] = new Queen(5, new Vector2(4, 0), new Vector2(64 * 4, 0), ResourceManager.Instance.Textures[GameColor.Black.ToString().ToLower() + "_queen"], GameColor.Black); pieces[5] = new Bishop(6, new Vector2(5, 0), new Vector2(64 * 5, 0), ResourceManager.Instance.Textures[GameColor.Black.ToString().ToLower() + "_bishop"], GameColor.Black); pieces[6] = new Knight(7, new Vector2(6, 0), new Vector2(64 * 6, 0), ResourceManager.Instance.Textures[GameColor.Black.ToString().ToLower() + "_knight"], GameColor.Black); pieces[7] = new Castle(8, new Vector2(7, 0), new Vector2(64 * 7, 0), ResourceManager.Instance.Textures[GameColor.Black.ToString().ToLower() + "_castle"], GameColor.Black); for (int i = 8; i < 16; i++) { pieces[i] = pawns[i - 8]; } for (int y = 0, i = 0; y < 2; y++) { for (int x = 0; x < 8; x++) { ResourceManager.Instance.Fields[(int)pieces[i].Position.X, (int)pieces[i].Position.Y].Piece = pieces[i]; i++; } } return(pieces); }
private static ChessPiece GetNewPieceFromChar(char type, PieceMaterial material, Vector2D position) { ChessPiece piece = null; switch (type.ToString().ToUpper()) { case "Q": piece = new Queen(position, material); break; case "K": piece = new King(position, material); break; case "P": piece = new Pawn(position, material); break; case "N": piece = new Knight(position, material); break; case "B": piece = new Bishop(position, material); break; case "R": piece = new Rook(position, material); break; default: break; } return(piece); }
public void CanCreateBishop() { Bishop b = new Bishop(Colour.White); b.Name.ShouldBe("Bishop"); b.Colour.ShouldBe(Colour.White); }
public static Piece GetByRole(string role, Player color) { Piece p; switch (role) { case "queen": p = new Queen(color); break; case "rook": p = new Rook(color); break; case "bishop": p = new Bishop(color); break; case "knight": p = new Knight(color); break; case "pawn": p = new Pawn(color); break; default: p = null; break; } return(p); }
public void Whether_Bishop_CantMoveToIncorrectSquare_On_CanMoveTo() { var board = new Board(); var bishop = new Bishop(new Square(4, 4), board, PieceColor.White); Assert.That(bishop.CanMoveTo(new Square(6, 5)), Is.False); }
public void EatOpponent(int sourceRow, int sourceColumn, bool isBlack, int destinationRow, int destinationColumn, bool result) { var rook = new Rook { Row = 0, Column = 0, IsBlack = !isBlack }; Formation.Pieces.Add(rook); var bishop = new Bishop { Row = sourceRow, Column = sourceColumn, IsBlack = isBlack }; var targetField = new Field(destinationRow, destinationColumn); Assert.That(bishop.CanMove(targetField), Is.EqualTo(result)); Assert.That(Formation.Pieces.Contains(rook)); bishop.TryConsumeAtTargetField(targetField); Assert.That(Formation.Pieces.Contains(rook), Is.False); Assert.That(bishop.Column, Is.EqualTo(targetField.Column)); Assert.That(bishop.Row, Is.EqualTo(targetField.Row)); }
public bool PromotePieceTo(Vector2Int from, string promotionPiece) { if (boardState[from.x, from.y] != null && PromotionPossible(from)) { string playerColor = boardState[from.x, from.y].Color; Console.Write(playerColor + " is promoting from " + from.x + "," + from.y + " to " + promotionPiece); Piece piece = null; RemovePiece(boardState[from.x, from.y]); if (promotionPiece == "QU") { piece = new Queen(this, playerColor); } if (promotionPiece == "TO") { piece = new Tower(this, playerColor); } if (promotionPiece == "BI") { piece = new Bishop(this, playerColor); } if (promotionPiece == "KN") { piece = new Knight(this, playerColor); } AddPiece(piece, from); return(true); } return(false); }
// *** OPERATIONS *** // public void AddChessPieceTypes() { AddPieceType(Queen = new Queen("Queen", "Q", 950, 950)); AddPieceType(Rook = new Rook("Rook", "R", 475, 500)); AddPieceType(Bishop = new Bishop("Bishop", "B", 350, 350)); AddPieceType(Knight = new Knight("Knight", "N", 285, 285)); }
public override Piece Clone() { Bishop clone = new Bishop(chess, team); clone.position = position; return(clone); }
public void Bishop_CanMove_Diagonally() { var board = new Board(); var bishop = new Bishop(Player.White); board.AddPiece(Square.At(4, 4), bishop); var moves = bishop.GetAvailableMoves(board); var expectedMoves = new List <Square>(); //Checking the backwards diagonal, i.e. 0,0 1,1, 2,2 for (var i = 0; i < 8; i++) { expectedMoves.Add(Square.At(i, i)); } //Checking the forwards diagonal i.e. 5,3 6,2 7,1 for (var i = 1; i < 8; i++) { expectedMoves.Add(Square.At(i, 8 - i)); } //Get rid of our starting location. expectedMoves.RemoveAll(s => s == Square.At(4, 4)); moves.ShouldAllBeEquivalentTo(expectedMoves); }
public static Piece GetType(string s, ChessColor color) { Piece p; switch (s) { case "Bishop": p = new Bishop(color); break; case "King": p = new King(color); break; case "Knight": p = new Knight(color); break; case "Pawn": p = new Pawn(color); break; case "Queen": p = new Queen(color); break; case "Rook": p = new Rook(color); break; default: throw new Exception("Piece unknown : " + s); } return(p); }
/// <summary>Initializes a new instance of <see cref="ChessGame"/>.</summary> public ChessGame() { Moves = new List <Move>(); var whitePawn = new Pawn(Player.White); var whiteRook = new Rook(Player.White); var whiteKnight = new Knight(Player.White); var whiteBishop = new Bishop(Player.White); var whiteQueen = new Queen(Player.White); var whiteKing = new King(Player.White); var blackPawn = new Pawn(Player.Black); var blackRook = new Rook(Player.Black); var blackKnight = new Knight(Player.Black); var blackBishop = new Bishop(Player.Black); var blackQueen = new Queen(Player.Black); var blackKing = new King(Player.Black); Board = new Piece?[][] { new Piece?[] { whiteRook, whiteKnight, whiteBishop, whiteQueen, whiteKing, whiteBishop, whiteKnight, whiteRook }, new Piece?[] { whitePawn, whitePawn, whitePawn, whitePawn, whitePawn, whitePawn, whitePawn, whitePawn }, new Piece?[] { null, null, null, null, null, null, null, null }, new Piece?[] { null, null, null, null, null, null, null, null }, new Piece?[] { null, null, null, null, null, null, null, null }, new Piece?[] { null, null, null, null, null, null, null, null }, new Piece?[] { blackPawn, blackPawn, blackPawn, blackPawn, blackPawn, blackPawn, blackPawn, blackPawn }, new Piece?[] { blackRook, blackKnight, blackBishop, blackQueen, blackKing, blackBishop, blackKnight, blackRook } }; }
// *** OPERATIONS *** // public void AddChessPieceTypes() { AddPieceType(Rook = new Rook("Rook", "R", 500, 525)); AddPieceType(Bishop = new Bishop("Bishop", "B", 325, 330)); AddPieceType(Knight = new Knight("Knight", "N", 325, 325)); AddPieceType(Queen = new Queen("Queen", "Q", 950, 1000)); }
public void DescribeSimpleMovements() { var bishop = new Bishop(PlayerType.Black, "8h"); string moveDescription = bishop.Move("6f"); Assert.Equal("B8h-6f", moveDescription); }
public static Piece GetType(string s, ChessColor color) { Piece p; switch (s) { case "Bishop": p = new Bishop(color); break; case "King": p = new King(color); break; case "Knight": p = new Knight(color); break; case "Pawn": p = new Pawn(color); break; case "Queen": p = new Queen(color); break; case "Rook": p = new Rook(color); break; default: throw new Exception("Piece unknown : " + s); } return p; }
// *** OPERATIONS *** // public void AddChessPieceTypes() { AddPieceType(Queen = new Queen("Queen", "Q", 1025, 1250)); AddPieceType(Rook = new Rook("Rook", "R", 550, 600)); AddPieceType(Bishop = new Bishop("Bishop", "B", 375, 375)); AddPieceType(Knight = new Knight("Knight", "N", 275, 275)); }
/// <summary> /// Add a piece to the board /// </summary> /// <param name="pieceIndex">The square to add the piece to</param> /// <param name="pieceName">The name of the piece type</param> /// <param name="owner">What colour it should be, null for promotion</param> public void SpecialAdd(int pieceIndex, string pieceName, string owner) { Piece piece = new Pawn(0, 0, Color.White); var x = (pieceIndex % 8) + 1; var y = (pieceIndex / 8) + 1; var ownerColour = Color.Black; if (owner.Equals("NULL")) { ownerColour = (y == 1 ? _board.WhiteColour : _board.BlackColour); } else if (owner.Equals("WHITE")) { ownerColour = _board.WhiteColour; } else if (owner.Equals("BLACK")) { ownerColour = _board.BlackColour; } switch (pieceName) { case "Pawn": piece = new Pawn(x, y, ownerColour); break; case "Rook": piece = new Rook(x, y, ownerColour); break; case "Bishop": piece = new Bishop(x, y, ownerColour); break; case "Knight": piece = new Knight(x, y, ownerColour); break; case "Queen": piece = new Queen(x, y, ownerColour); break; // Shouldn't be needed case "King": piece = new King(x, y, ownerColour); break; } // Remove any old piece _board.Pieces.Remove(_board.GetPiece(x, y)); // Add the new piece _board.Pieces.Add(piece); foreach (var pieces in _board.Pieces) { pieces.GetMoves(_board, true); } // Redraw the board Invalidate(); }
private Bitboard() { Rook = new Rook(); Bishop = new Bishop(); _pawn = new Pawn(); _king = new King(); _knight = new Knight(); }
public void Whether_King_CantMoveToBeatenSquare_On_CanMoveTo() { var board = new Board(); var king = new King(new Square(4, 4), board, PieceColor.White); var bishop = new Bishop(new Square(4, 6), board, PieceColor.Black); Assert.That(king.CanMoveTo(new Square(5, 5)), Is.False); }
public void Whether_King_CantEscapeFromBishopOnTheSameDiagonal_OnCanMoveTo() { var board = new Board(); var king = new King(new Square(4, 4), board, PieceColor.White); var bishop = new Bishop(new Square(5, 5), board, PieceColor.Black); Assert.That(king.CanMoveTo(new Square(3, 3)), Is.False); }
public void Whether_Bishop_CantJumpOverAnotherPiece_On_CanMoveTo(PieceColor pieceColor) { var board = new Board(); var bishop = new Bishop(new Square(4, 4), board, PieceColor.White); var knight = new Knight(new Square(5, 5), board, pieceColor); Assert.That(bishop.CanMoveTo(new Square(6, 6)), Is.False); }
public void AllowValidMoves(Player player, string positionFrom, string positionTo) { var bishop = new Bishop(player, positionFrom); var isMoveLegal = bishop.IsMoveLegal(positionTo); Assert.True(isMoveLegal); }
public void EatTest() { var a = new Pawn(); var b = new Bishop(); a.Eat(b); Equals(!b.IsAlive); }
public void ShouldGetNullWhenInstanceIsPawn() { var bishop = new Bishop(new Position(EColumn.H, ELine.Seven), EColor.White, _board); var pawn = new Pawn(new Position(EColumn.A, ELine.One), EColor.White, _board, GameplayBuilder.New().Build()); var newPiece = Utils.GetBuildedPieceFromAnother(pawn, bishop.Position, pawn.Color, _board); Assert.Null(newPiece); }
private void InitializeBishops() { _board[0][2] = new Bishop(_positionsXY[0][2], TeamColor.White); _board[0][BoardSize - 3] = new Bishop(_positionsXY[0][BoardSize - 3], TeamColor.White); _board[BoardSize - 1][2] = new Bishop(_positionsXY[BoardSize - 1][2], TeamColor.Black); _board[BoardSize - 1][BoardSize - 3] = new Bishop(_positionsXY[BoardSize - 1][BoardSize - 3], TeamColor.Black); }
public void constructor_blackBishop() { Piece piece = new Bishop("Black", new Point(0, 0), new ChessBoard()); PieceManager pm = new PieceManager(piece, new Game()); Assert.AreEqual(pm.Owner, Players.BlackPlayer); Assert.AreEqual(pm.Type, PieceTypes.Bishop); }
public void Whether_Bishop_CantMoveOutsideTheBoard_On_CanMoveTo() { var board = new Board(); var bishop = new Bishop(new Square(1, 1), board, PieceColor.White); Assert.That(bishop.PossibleMoves().Count() == 7); Assert.That(bishop.CanMoveTo(new Square(-1, -1)), Is.False); }
public void Whether_Bishop_CantMoveToOccupiedSquare_On_CanMoveTo() { var board = new Board(); var bishop = new Bishop(new Square(4, 4), board, PieceColor.White); var anotherKnight = new Knight(new Square(6, 6), board, PieceColor.White); Assert.That(bishop.CanMoveTo(new Square(6, 6)), Is.False); }
public void EatTest() { var a = new Knight(); var b = new Bishop(); a.Eat(b); Assert.True(!b.IsAlive); }
public void NotAllowIllegalMoves(Player player, string positionFrom, string positionTo) { var bishop = new Bishop(player, positionFrom); var isMoveLegal = bishop.IsMoveLegal(positionTo); Assert.False(isMoveLegal); }
public override ChessPiece Clone(Board board) { var newBishopToReturn = new Bishop(board, Color) { MovingStrategy = MovingStrategy.Clone(board) }; return newBishopToReturn; }
/// <summary> /// Initializes a new instance of the <see cref="PlayerChess"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> public PlayerChess(IPieceColor color, Gameboard gameboard) : base(color) { IPiece newPiece; int offset = 0; this.gameboard = gameboard; this.selectedPiece = null; if (color == IPieceColor.White) { offset = 7; } else if (color == IPieceColor.Black) { offset = 0; } for (int i = 0; i < 8; i++) { newPiece = new Pawn(color, gameboard, new Position(i, Math.Abs(offset - 1))); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); } newPiece = new Rook(color, gameboard, new Position(0, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Rook(color, gameboard, new Position(7, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Knight(color, gameboard, new Position(1, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Knight(color, gameboard, new Position(6, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Bishop(color, gameboard, new Position(2, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Bishop(color, gameboard, new Position(5, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Queen(color, gameboard, new Position(3, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new King(color, gameboard, new Position(4, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); this.King = newPiece; }
public static void TestThrowIfNull() { Assert.Throws<ArgumentNullException>(delegate () { object value = null; ChessUtilities.ThrowIfNull(value, "value"); }); Assert.DoesNotThrow(delegate () { Piece piece = new Bishop(Player.White); ChessUtilities.ThrowIfNull(piece, "piece"); }); }
public void TestFromFenValid() { const string FEN_STRING = "pQ4N1/3k3R/1r4n1/KbBbBppP/8/8/q7/7n"; FENSerializer ser = new FENSerializer(); Board expected = new Board(null); Board actual; // Setup expected['8', 'A'] = new Pawn('b'); expected['8', 'B'] = new Queen('w'); expected['8', 'G'] = new Knight('w'); expected['7', 'D'] = new King('b'); expected['7', 'H'] = new Rook('w'); expected['6', 'B'] = new Rook('b'); expected['6', 'G'] = new Knight('b'); expected['5', 'A'] = new King('w'); expected['5', 'B'] = new Bishop('b'); expected['5', 'C'] = new Bishop('w'); expected['5', 'D'] = new Bishop('b'); expected['5', 'E'] = new Bishop('w'); expected['5', 'F'] = new Pawn('b'); expected['5', 'G'] = new Pawn('b'); expected['5', 'H'] = new Pawn('w'); expected['2', 'A'] = new Queen('b'); expected['1', 'H'] = new Knight('b'); // Act actual = ser.Deserialize(FEN_STRING); // Test for (int file = 0; file < Board.NUM_FILES; file++) { for (int row = 0; row < Board.NUM_ROWS; row++) { Piece expectedPiece = expected[row, file]; Piece actualPiece = actual[row, file]; bool areEqual = Piece.AreEqual(expectedPiece, actualPiece); Assert.IsTrue(areEqual); } } }
public void placeBlackFigures() { Figure[] pawns = new Figure[8]; Figure[] otherFigures = new Figure[8]; char currentChar = 'A'; char charPositionPawn = 'A'; for (int i = 0; i < 8; i++) { pawns[i] = new Pawn(charPositionPawn, 2, false); charPositionPawn++; if ((currentChar == 'A') || (currentChar == 'H')) { otherFigures[i] = new Rook(currentChar, 1, false); } else if ((currentChar == 'B') || (currentChar == 'G')) { otherFigures[i] = new Knight(currentChar, 1, false); } else if ((currentChar == 'C') || (currentChar == 'F')) { otherFigures[i] = new Bishop(currentChar, 1, false); } else if (currentChar == 'E') { otherFigures[i] = new King(currentChar, 1, false); } else { otherFigures[i] = new Queen(currentChar, 1, false); } currentChar++; } for (int i = 0; i < 8; i++) { placeFigure(pawns[i]); placeFigure(otherFigures[i]); } }
public static void TestInEquality_OneIsNull() { Piece piece1 = new Rook(Player.White); Piece piece2 = null; Assert.AreNotEqual(piece1, piece2, "piece1 and piece2 are equal"); Assert.False(piece1.Equals(piece2), "piece1.Equals(piece2) should be false"); Assert.False(piece1 == piece2, "piece1 == piece2 should be false"); Assert.False(piece2 == piece1, "piece2 == piece1 should be false"); Assert.True(piece1 != piece2, "piece1 != piece2 should be True"); Assert.True(piece2 != piece1, "piece2 != piece1 should be True"); piece1 = null; piece2 = new Bishop(Player.Black); Assert.AreNotEqual(piece1, piece2, "piece1 and piece2 are equal"); Assert.False(piece2.Equals(piece1), "piece1.Equals(piece2) should be false"); Assert.False(piece1 == piece2, "piece1 == piece2 should be false"); Assert.False(piece2 == piece1, "piece2 == piece1 should be false"); Assert.True(piece1 != piece2, "piece1 != piece2 should be True"); Assert.True(piece2 != piece1, "piece2 != piece1 should be True"); }
private static void GetPieceForFENChar(char fench, ChessSide whites, ChessSide blacks, int rank, int file, out ChessPiece piece) { ColorType color; ChessSide myside, oppside; if (Char.IsUpper (fench)) { color = ColorType.WHITE; myside = whites; oppside = blacks; } else { color = ColorType.BLACK; myside = blacks; oppside = whites; } char ch = Char.ToLower (fench); switch (ch) { case 'p': piece = new Pawn (color, rank, file, myside, oppside); break; case 'k': piece = new King (color, rank, file, myside, oppside); break; case 'q': piece = new Queen (color, rank, file, myside, oppside); break; case 'b': piece = new Bishop (color, rank, file, myside, oppside); break; case 's': piece = new Knight (color, rank, file, myside, oppside); break; case 'n': piece = new Knight (color, rank, file, myside, oppside); break; case 'r': piece = new Rook (color, rank, file, myside, oppside); break; default: throw new ChessException (Catalog.GetString("Invalid piece type ") + ch); } }
// images[blksq/whtsq][side][idx] - idx = {KING, QUEEN, ROOK, KNIGHT, BISHOP} public ChessPiece createPiece(PieceType type, ColorType color, int rank, int file) { ChessPiece piece = null; ChessSide myside, oppside; if (color == ColorType.WHITE) { myside = whites; oppside = blacks; } else { myside = blacks; oppside = blacks; } switch (type) { case PieceType.KING: piece = new King (color, rank, file, myside, oppside); break; case PieceType.QUEEN: piece = new Queen (color, rank, file, myside, oppside); break; case PieceType.ROOK: piece = new Rook (color, rank, file, myside, oppside); break; case PieceType.KNIGHT: piece = new Knight (color, rank, file, myside, oppside); break; case PieceType.BISHOP: piece = new Bishop (color, rank, file, myside, oppside); break; default: return null; } return piece; }
public void SetUp() { Target = new Bishop(); }
public void Returns_2_2_For_1_1() { var bishop = new Bishop(); Assert.IsTrue(this.GetMoves(1, 1).Any(bc => bc.X == 2 && bc.Y == 2)); }
public void BeforeEachTest() { Target = new Bishop(); }
/* Numbers of chessmen are: 0 - King, 1 - Queen, 2 - Bishop, 3 - Knight, 4 - Tower, * 5 - Pawn of Queen, 6 - Pawn of Bishop, 7 - Pawn of Knight, 8 - Pawn of Tower. * Numbers of players are: 0 - Yellow, 1 - Red, 2 - Blue, 3 - Black. * Number of arrangement - numberOfArrangement. */ public Chessman CreateNewChessman(string playersColor, string chessmanName, Chessboard chessboard) { int indexOfPlayer = -1; int indexOfChessman = -1; ChessmenParameters chessmanParam = new ChessmenParameters(); Chessman result; //gets number of player switch (playersColor) { case "Yellow": indexOfPlayer = 0; break; case "Red": indexOfPlayer = 1; break; case "Blue": indexOfPlayer = 2; break; case "Black": indexOfPlayer = 3; break; default: { MessageBox.Show("Внутренняя ошибка, невозможно выполнить действие"); return null; } } //gets number of chessman switch (chessmanName) { case "King": indexOfChessman = 0; break; case "Queen": indexOfChessman = 1; break; case "Bishop": indexOfChessman = 2; break; case "Knight": indexOfChessman = 3; break; case "Tower": indexOfChessman = 4; break; case "PawnOfQueen": indexOfChessman = 5; chessmanName = "Pawn of Queen"; break; case "PawnOfBishop": indexOfChessman = 6; chessmanName = "Pawn of Bishop"; break; case "PawnOfKnight": indexOfChessman = 7; chessmanName = "Pawn of Knight"; break; case "PawnOfTower": indexOfChessman = 8; chessmanName = "Pawn of Tower"; break; default: { MessageBox.Show("Внутренняя ошибка, невозможно выполнить действие"); return null; } } //set parameters chessmanParam.horizontal = positionOfChessmen[numberOfArrangement, indexOfPlayer, indexOfChessman, 1]; chessmanParam.vertical = positionOfChessmen[numberOfArrangement, indexOfPlayer, indexOfChessman, 0]; chessmanParam.ruNameNominative = GetNominativeRu(indexOfPlayer, indexOfChessman); chessmanParam.engName = playersColor + ' ' + chessmanName; chessmanParam.chessmanBitmap = chessmanBitmap[indexOfPlayer, indexOfChessman]; chessmanParam.ruNameAccusative = GetAccusativeRu(indexOfPlayer, indexOfChessman); chessmanParam.kindOfChessman = (ChessmenNames)indexOfChessman; chessmanParam.player = (Players)indexOfPlayer; chessmanParam.ruAttack = GetAttackRu(indexOfChessman); chessmanParam.ruMove = GetMoveRu(indexOfChessman); switch (indexOfChessman) { case 0: result = new King(chessmanParam, chessboard); break; case 1: result = new Queen(chessmanParam, chessboard); break; case 2: result = new Bishop(chessmanParam, chessboard); break; case 3: result = new Knight(chessmanParam, chessboard); break; case 4: result = new Tower(chessmanParam, chessboard); break; case 5: result = GetNewCorrectPawn(chessmanParam, chessboard); break; case 6: result = GetNewCorrectPawn(chessmanParam, chessboard); break; case 7: result = GetNewCorrectPawn(chessmanParam, chessboard); break; case 8: result = GetNewCorrectPawn(chessmanParam, chessboard); break; default: { result = null; break; } } return result; }
public static void initGame() { Console.Clear(); //initalize game Random rnd = new Random (); if (rnd.Next(2)==1) { State.playerOneColor = "White"; } else { State.playerOneColor = "Black"; } State.moveNumber = 0; State.turn = "White"; State.strength = 18; //Initiate White pieces Piece k2 = new King (4, 0, "White"); Piece q1 = new Queen(3, 0, "White"); Piece r1 = new Rook(0, 0, "White"); Piece r2 = new Rook(7, 0, "White"); Piece b1 = new Bishop (5, 0, "White"); Piece b2 = new Bishop (2, 0, "White"); Piece n1 = new Knight (1, 0, "White"); Piece n2 = new Knight (6, 0, "White"); //pawns Piece p0 = new Pawn (0, 1, "White"); Piece p1 = new Pawn (1, 1, "White"); Piece p2 = new Pawn (2, 1, "White"); Piece p3 = new Pawn (3, 1, "White"); Piece p4 = new Pawn (4, 1, "White"); Piece p5 = new Pawn (5, 1, "White"); Piece p6 = new Pawn (6, 1, "White"); Piece p7 = new Pawn (7, 1, "White"); //Initiate Black pieces Piece k1 = new King (4, 7, "Black"); Piece q2 = new Queen (3, 7, "Black"); Piece r3 = new Rook (0, 7, "Black"); Piece r4 = new Rook (7, 7, "Black"); Piece b3 = new Bishop(5, 7, "Black"); Piece b4 = new Bishop(2, 7, "Black"); Piece n3 = new Knight (1,7, "Black"); Piece n4 = new Knight (6,7, "Black"); //pawns Piece p8 = new Pawn (0, 6, "Black"); Piece p9 = new Pawn (1, 6, "Black"); Piece p10 = new Pawn (2, 6, "Black"); Piece p11 = new Pawn (3, 6, "Black"); Piece p12 = new Pawn (4, 6, "Black"); Piece p13 = new Pawn (5, 6, "Black"); Piece p14 = new Pawn (6, 6, "Black"); Piece p15 = new Pawn (7, 6, "Black"); //Add pieces to piece array Piece[] pieces = new Piece[] {k1, k2, q1, q2, r1, r2, r3, r4, n1, n2, n3, n4, b1, b2, b3, b4, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15}; //Send setup back to the state State.addPiece(pieces); }
private bool Equals(Bishop other) { return !ReferenceEquals(null, other) && Color == other.Color; }
private static IPiece InitialPieceAtLocation(Rank rank, File file) { var emptyRanks = new[] { Rank.Three, Rank.Four, Rank.Five, Rank.Six}; if (emptyRanks.Contains(rank)) { return null; } var colour = PlayerColour.Black; if (rank == Rank.One || rank == Rank.Two) { colour = PlayerColour.White; } IPiece piece = new Rook(colour); if (rank == Rank.Seven || rank == Rank.Two) { piece = new Pawn(colour); } else if (file == File.B || file == File.G) { piece = new Knight(colour); } else if (file == File.C || file == File.F) { piece = new Bishop(colour); } else if (file == File.D) { piece = new Queen(colour); } else if (file == File.E) { piece = new King(colour); } return piece; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here int width = Math.Min(this.Window.ClientBounds.Width, this.Window.ClientBounds.Height); for (int i = 0; i < 8; i++) //define pieces and initial positions { //Rectangle position = new Rectangle(0 + width / 8 * i, width / 8, width / 8, width / 8); //Rectangle position2 = new Rectangle(0 + width / 8 * i, width * 6/ 8, width/8, width/ 8); pieces[i + 16] = new Pawn(this, i ,1); pieces[i] = new Pawn(this, i, 6); } pieces[8] = new King(this, 4, 7); pieces[9] = new Queen(this, 3, 7); pieces[10] = new Rook(this, 0, 7); pieces[11] = new Rook(this, 7, 7); pieces[12] = new Knight(this, 1, 7); pieces[13] = new Knight(this, 6, 7); pieces[14] = new Bishop(this, 2, 7); pieces[15] = new Bishop(this, 5, 7); pieces[24] = new King(this, 4, 0); pieces[25] = new Queen(this, 3, 0); pieces[26] = new Rook(this, 0, 0); pieces[27] = new Rook(this, 7, 0); pieces[28] = new Knight(this, 1, 0); pieces[29] = new Knight(this, 6, 0); pieces[30] = new Bishop(this, 2, 0); pieces[31] = new Bishop(this, 5, 0); this.IsMouseVisible = true; board = new int[8, 8]; turn = false; gameover = 0; movementHandler = new MovementHandler(this); //Components.Add(movementHandler); base.Initialize(); }