public void CheckIfTheAddFigureMethodThrowsCorrectlyNullReferenceExeption() { var board = new Board(); var position = new Position(-1, -1); IFigure figure = new King(FigureSign.K); board.AddFigure(figure, position); }
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; }
public void BeforeTests() { _board = new Board(8); _rook = new Rook(PlayerColor.White); _king = new King(PlayerColor.Black); _referee = new Referee(new MoveAttemptHandler()); }
// Use this for initialization void Start() { myQueen = new Queen(); myKing = new King(); currentCharacter = myQueen; currentCharacter.outfit = queenOutfit; currentCharacter.weapon.setWeapon(knife, "knife"); }
public static ICard Of(CardSuit cardSuit) { var king = new King { _CardSuit = cardSuit }; return king; }
public void CheckIfTheAddFigureMethodThrowsCorrectlyIndexOutOfRangeException() { var board = new Board(); var position = new Position(9, 9); var figureSign = FigureSign.K; var figure = new King(figureSign); board.AddFigure(figure, position); }
public void King_TestEmptyFigurePostionSet() { int[] positions = { }; King myKing = new King(); myKing.FigurePosition = positions; }
public void King_TestEmptyFigureExistingMovesSet() { bool[] positions = { }; King myKing = new King(); myKing.FigureExistingMoves = positions; }
public void CheckIfGetFigureAtPositionReturnsTheCorrectFigure() { var board = new Board(); var position = new Position(1, 1); var figureSign = FigureSign.K; var figure = new King(figureSign); board.AddFigure(figure, position); Assert.AreEqual(figure, board.GetFigureAtPosition(position)); }
public void King_TestDefaultFigurePositionGet() { int[] expected = { 9, 10 }; King myKing = new King(); CollectionAssert.AreEqual(expected, myKing.FigurePosition); }
public void CheckIfRemoveFigureRemovesTheFigure() { var board = new Board(); var position = new Position(1, 1); var figureSign = FigureSign.K; var figure = new King(figureSign); board.AddFigure(figure, position); board.RemoveFigure(figure, position); Assert.AreNotEqual(figure, board.GetFigureAtPosition(position)); }
public void CheckForKingExit_WithInvalidValueOutsideOfBoard() { Pawn firstPawn = new Pawn('A', new string[] { "ADL", "ADR" }, new int[] { 2, 4 }); Pawn secondPawn = new Pawn('B', new string[] { "BDL", "BDR" }, new int[] { 2, 8 }); Pawn thirdPawn = new Pawn('C', new string[] { "CDL", "CDR" }, new int[] { 2, 12 }); Pawn fourthPawn = new Pawn('D', new string[] { "DDL", "DDR" }, new int[] { 2, 16 }); King theKing = new King(); GameBoard gameBoard = new GameBoard(); GameEngine myTestEngine = new GameEngine(gameBoard, firstPawn, secondPawn, thirdPawn, fourthPawn, theKing); myTestEngine.InitGame(); myTestEngine.CheckForKingExit(0); }
public void King_TestDefaultFigureExistingMovesGet() { bool[] expected = { true, true, true, true }; King myKing = new King(); CollectionAssert.AreEqual(expected, myKing.FigureExistingMoves); }
public static void TestInequality_DifferentPieceAndPlayer() { Piece piece1 = new King(Player.White); Piece piece2 = new Queen(Player.Black); Assert.AreNotEqual(piece1, piece2, "piece1 and piece2 are equal"); Assert.False(piece1.Equals(piece2), "piece1.Equals(piece2) should be false"); Assert.False(piece2.Equals(piece1), "piece2.Equals(piece1) 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"); Assert.AreNotEqual(piece1.GetHashCode(), piece2.GetHashCode(), "Hash codes are equal"); }
public static void TestEquality() { Piece piece1 = new King(Player.White); Piece piece2 = new King(Player.White); Assert.AreEqual(piece1, piece2, "piece1 and piece2 are not equal"); Assert.True(piece1.Equals(piece2), "piece1.Equals(piece2) should be True"); Assert.True(piece2.Equals(piece1), "piece2.Equals(piece1) should be True"); Assert.True(piece1 == piece2, "piece1 == piece2 should be True"); Assert.True(piece2 == piece1, "piece2 == piece1 should be True"); Assert.False(piece1 != piece2, "piece1 != piece2 should be false"); Assert.False(piece2 != piece1, "piece2 != piece1 should be false"); Assert.AreEqual(piece1.GetHashCode(), piece2.GetHashCode(), "Hash codes are different"); }
public void CheckForKingExit_KingHasExit() { Pawn firstPawn = new Pawn('A', new string[] { "ADL", "ADR" }, new int[] { 2, 4 }); Pawn secondPawn = new Pawn('B', new string[] { "BDL", "BDR" }, new int[] { 2, 8 }); Pawn thirdPawn = new Pawn('C', new string[] { "CDL", "CDR" }, new int[] { 2, 12 }); Pawn fourthPawn = new Pawn('D', new string[] { "DDL", "DDR" }, new int[] { 9, 16 }); King theKing = new King(); GameBoard gameBoard = new GameBoard(); GameEngine myTestEngine = new GameEngine(gameBoard, firstPawn, secondPawn, thirdPawn, fourthPawn, theKing); myTestEngine.InitGame(); Assert.IsTrue(myTestEngine.CheckForKingExit(2)); }
public void King_TestDefaultValidInputsGet() { string[] expected = { "KUL", "KUR", "KDL", "KDR" }; King myKing = new King(); CollectionAssert.AreEqual(expected, myKing.ValidFigureInputs); }
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 void resetMap() { resetAllStats(); map = new Tile[MapGenerator.BoardWidth, MapGenerator.BoardHeight]; for (int x = 0; x < MapGenerator.BoardWidth; x++) { for (int y = 0; y < MapGenerator.BoardHeight; y++) { Tile tileAtPoint = MapGenerator.getTileAtPoint(x, y); Tile newTile = new Tile(); newTile.setTileType(tileAtPoint.getCurrentTileType()); if (tileAtPoint.getCurrentEntity() != null) { Entity newEntity = null; if (tileAtPoint.getCurrentEntity() is King) { newEntity = new King(); } else { newEntity = new Minion(); } newEntity.entityType = tileAtPoint.getCurrentEntity().entityType; if (checkEntityIsFriendly(newEntity)) { friendlyEntities.Add(newEntity); } else if (checkEntityIsEnemy(newEntity)) { enemyEnities.Add(newEntity); } newTile.setEntity(newEntity); } if (checkEntityIsEnemy(tileAtPoint.currentTileType)) { tilesControlled++; } if (checkEntityIsFriendly(tileAtPoint.currentTileType)) { enemyTilesControlled++; } } } }
public void SetStatus(King k, int place) { switch(place) { case 1: firstKing.text = k.name; firstStats[0].text = k.raha.ToString(); firstStats[1].text = k.suosio.ToString(); firstStats[2].text = k.rauha.ToString(); break; case 2: secondKing.text = k.name; secondStats[0].text = k.raha.ToString(); secondStats[1].text = k.suosio.ToString(); secondStats[2].text = k.rauha.ToString(); break; case 3: thirdKing.text = k.name; thirdStats[0].text = k.raha.ToString(); thirdStats[1].text = k.suosio.ToString(); thirdStats[2].text = k.rauha.ToString(); break; } }
public Board(bool player1) { Turn = true; TurnNumber = 0; FullMoveNumber = 0; this.player1 = player1; ChessBoard = new PieceBase[Constants.Size, Constants.Size]; WhitePieces = new HashSet <PieceBase>(); BlackPieces = new HashSet <PieceBase>(); P1RRookCanCastling = true; P1LRookCanCastling = true; P2RRookCanCastling = true; P2LRookCanCastling = true; ChessBoard[0, 1] = new Pawn(player1, 0, 1); ChessBoard[1, 1] = new Pawn(player1, 1, 1); ChessBoard[2, 1] = new Pawn(player1, 2, 1); ChessBoard[3, 1] = new Pawn(player1, 3, 1); ChessBoard[4, 1] = new Pawn(player1, 4, 1); ChessBoard[5, 1] = new Pawn(player1, 5, 1); ChessBoard[6, 1] = new Pawn(player1, 6, 1); ChessBoard[7, 1] = new Pawn(player1, 7, 1); ChessBoard[0, 6] = new Pawn(!player1, 0, 6); ChessBoard[1, 6] = new Pawn(!player1, 1, 6); ChessBoard[2, 6] = new Pawn(!player1, 2, 6); ChessBoard[3, 6] = new Pawn(!player1, 3, 6); ChessBoard[4, 6] = new Pawn(!player1, 4, 6); ChessBoard[5, 6] = new Pawn(!player1, 5, 6); ChessBoard[6, 6] = new Pawn(!player1, 6, 6); ChessBoard[7, 6] = new Pawn(!player1, 7, 6); ChessBoard[0, 0] = new Rook(player1, 0, 0); ChessBoard[7, 0] = new Rook(player1, 7, 0); ChessBoard[0, 7] = new Rook(!player1, 0, 7); ChessBoard[7, 7] = new Rook(!player1, 7, 7); ChessBoard[1, 0] = new Knight(player1, 1, 0); ChessBoard[6, 0] = new Knight(player1, 6, 0); ChessBoard[1, 7] = new Knight(!player1, 1, 7); ChessBoard[6, 7] = new Knight(!player1, 6, 7); ChessBoard[2, 0] = new Bishop(player1, 2, 0); ChessBoard[5, 0] = new Bishop(player1, 5, 0); ChessBoard[2, 7] = new Bishop(!player1, 2, 7); ChessBoard[5, 7] = new Bishop(!player1, 5, 7); ChessBoard[4, 0] = new King(player1, 4, 0); ChessBoard[4, 7] = new King(!player1, 4, 7); ChessBoard[3, 0] = new Queen(player1, 3, 0); ChessBoard[3, 7] = new Queen(!player1, 3, 7); // creates 2 arrays with same color pieces for (int i = Constants.ForStart; i < Constants.ColorPieces / 2; i++) { WhitePieces.Add(ChessBoard[i, 1]); BlackPieces.Add(ChessBoard[i, 6]); } for (int i = Constants.ForStart; i < Constants.ColorPieces / 2; i++) { WhitePieces.Add(ChessBoard[i, 0]); BlackPieces.Add(ChessBoard[i, 7]); } for (int i = Constants.ForStart; i < Constants.Size; i++) { for (int j = Constants.EmptyPieceStartLine; j < Constants.EmptyPieceEndLine; j++) { ChessBoard[i, j] = null; } } }
public static Move ParseSan(ChessGame game, string san) { Player player = game.WhoseTurn; string move = san.TrimEnd('#', '?', '!', '+').Trim(); Position origin = null; Position destination = null; Piece piece = null; char? promotion = null; if (move.Length > 2) { string possiblePromotionPiece = move.Substring(move.Length - 2).ToUpperInvariant(); if (possiblePromotionPiece[0] == '=') { promotion = possiblePromotionPiece[1]; move = move.Remove(move.Length - 2, 2); } } if (move.ToUpperInvariant() == "O-O") { int r = player == Player.White ? 1 : 8; origin = new Position(File.E, r); destination = new Position(File.G, r); piece = new King(player); } else if (move.ToUpperInvariant() == "O-O-O") { int r = player == Player.White ? 1 : 8; origin = new Position(File.E, r); destination = new Position(File.C, r); piece = new King(player); } if (piece == null) { piece = game.MapPgnCharToPiece(move[0], player); } if (!(piece is Pawn)) { move = move.Remove(0, 1); } int rankRestriction = -1; File fileRestriction = File.None; if (destination == null) { if (move[0] == 'x') { move = move.Remove(0, 1); } else if (move.Length == 4 && move[1] == 'x') { move = move.Remove(1, 1); } if (move.Length == 2) { destination = new Position(move); } else if (move.Length == 3) { if (char.IsDigit(move[0])) { rankRestriction = int.Parse(move[0].ToString()); } else { bool recognized = Enum.TryParse <File>(move[0].ToString(), true, out fileRestriction); if (!recognized) { throw new ArgumentException("unrecognized origin file."); } } destination = new Position(move.Remove(0, 1)); } else if (move.Length == 4) { origin = new Position(move.Substring(0, 2)); destination = new Position(move.Substring(2, 2)); } else { throw new ArgumentException("Invalid move."); } } if (origin != null) { var m = new Move(origin, destination, player, promotion); if (game.IsValidMove(m)) { return(m); } else { throw new ArgumentException("Invalid move."); } } else { Piece[][] board = game.GetBoard(); var validMoves = new List <Move>(); for (int r = 0; r < game.BoardHeight; r++) { if (rankRestriction != -1 && r != 8 - rankRestriction) { continue; } for (int f = 0; f < game.BoardWidth; f++) { if (fileRestriction != File.None && f != (int)fileRestriction) { continue; } if (board[r][f] != piece) { continue; } var m = new Move(new Position((File)f, 8 - r), destination, player, promotion); if (game.IsValidMove(m)) { validMoves.Add(m); } } } if (validMoves.Count == 0) { throw new ArgumentException("Invalid move."); } if (validMoves.Count > 1) { throw new ArgumentException("Ambiguous move."); } return(validMoves[0]); } }
// 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 ChessTile(bool botVSbot, bool isWhite, double pawnWeightOpp1, double rookWeightOpp1, double bishopWeightOpp1, double knightWeightOpp1, double queenWeightOpp1, double kingWeightOpp1, double pawnWeightOpp2, double rookWeightOpp2, double bishopWeightOpp2, double knightWeightOpp2, double queenWeightOpp2, double kingWeightOpp2) { this.IsWhite = isWhite; if (IsWhite) { oneHand = "white"; } else { otherHand = "white"; } Figures = new List <Figure>(); for (int i = 0; i < 8; i++) { Pawn p = new Pawn(); p.IsWhite = IsWhite; p.ImgPath = "addons/pawn_" + oneHand + ".png"; p.Coord = new int[2] { i, 6 }; p.Weight = pawnWeightOpp1; Figures.Add(p); } for (int i = 0; i < 8; i++) { Pawn p = new Pawn(); p.IsWhite = !IsWhite; p.ImgPath = "addons/pawn_" + otherHand + ".png"; p.Coord = new int[2] { i, 1 }; p.Weight = pawnWeightOpp2; Figures.Add(p); } for (int i = 0; i < 8; i += 7) { Rook r = new Rook(); r.IsWhite = IsWhite; r.ImgPath = "addons/rook_" + oneHand + ".png"; r.Coord = new int[2] { i, 7 }; r.Weight = rookWeightOpp1; Figures.Add(r); } for (int i = 0; i < 8; i += 7) { Rook r = new Rook(); r.IsWhite = !IsWhite; r.ImgPath = "addons/rook_" + otherHand + ".png"; r.Coord = new int[2] { i, 0 }; r.Weight = rookWeightOpp2; Figures.Add(r); } for (int i = 2; i < 8; i += 3) { Bishop b = new Bishop(); b.IsWhite = IsWhite; b.ImgPath = "addons/bishop_" + oneHand + ".png"; b.Coord = new int[2] { i, 7 }; b.Weight = bishopWeightOpp1; Figures.Add(b); } for (int i = 2; i < 8; i += 3) { Bishop b = new Bishop(); b.IsWhite = !IsWhite; b.ImgPath = "addons/bishop_" + otherHand + ".png"; b.Coord = new int[2] { i, 0 }; b.Weight = bishopWeightOpp2; Figures.Add(b); } for (int i = 1; i < 8; i += 5) { Knight kn = new Knight(); kn.IsWhite = IsWhite; kn.ImgPath = "addons/knight_" + oneHand + ".png"; kn.Coord = new int[2] { i, 7 }; kn.Weight = knightWeightOpp1; Figures.Add(kn); } for (int i = 1; i < 8; i += 5) { Knight kn = new Knight(); kn.IsWhite = !IsWhite; kn.ImgPath = "addons/knight_" + otherHand + ".png"; kn.Coord = new int[2] { i, 0 }; kn.Weight = knightWeightOpp2; Figures.Add(kn); } Queen q = new Queen(); q.IsWhite = IsWhite; q.ImgPath = "addons/queen_" + oneHand + ".png"; q.Coord = new int[2] { 3, 7 }; q.Weight = queenWeightOpp1; Figures.Add(q); q = new Queen(); q.IsWhite = !IsWhite; q.ImgPath = "addons/queen_" + otherHand + ".png"; q.Coord = new int[2] { 3, 0 }; q.Weight = queenWeightOpp2; Figures.Add(q); King k = new King(); k.IsWhite = IsWhite; k.ImgPath = "addons/king_" + oneHand + ".png"; k.Coord = new int[2] { 4, 7 }; k.Weight = kingWeightOpp1; Figures.Add(k); k = new King(); k.IsWhite = !IsWhite; k.ImgPath = "addons/king_" + otherHand + ".png"; k.Coord = new int[2] { 4, 0 }; k.Weight = kingWeightOpp2; Figures.Add(k); }
/// <summary> /// Возвращает список фигур атакующих заданного короля. /// </summary> /// <param name="color">Королю какого цвета поствлен шах.</param> public bool DetectCheck(King king) { return(GetFiguresAttackingFigure(king).Count > 0); }
private ChessFigure GetFigure(int row, int col) { ChessFigure figure = new Empty(row, col); // Black Figures if (row == 0) { if (col == 1 || col == 6) { figure = new Knight(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackKnight.png"); } if (col == 3) { figure = new Queen(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackQueen.png"); } if (col == 2 || col == 5) { figure = new Bishop(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackBishop.png"); } if (col == 4) { figure = new King(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackKing.png"); } if (col == 0 || col == 7) { figure = new Rook(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackRook.png"); } } // White Figures if (row == 7) { if (col == 1 || col == 6) { figure = new Knight(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhiteKnight.png"); } if (col == 3) { figure = new Queen(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhiteQueen.png"); } if (col == 2 || col == 5) { figure = new Bishop(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhiteBishop.png"); } if (col == 4) { figure = new King(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhiteKing.png"); } if (col == 0 || col == 7) { figure = new Rook(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhiteRook.png"); } } if (row == 1) { figure = new Pawn(row, col, "black", @"E:\Repos\Chess\Chess\Images\BlackPawn.png"); } if (row == 6) { figure = new Pawn(row, col, "white", @"E:\Repos\Chess\Chess\Images\WhitePawn.png"); } return(figure); }
public abstract void VisitKing(King king);
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; }
public static void CreateBattle(King king, King to_King) { new BattleContorl(king, to_King, BattleUiIndex); }
static void Main(string[] args) { string kingName = Console.ReadLine(); var king = new King(kingName); var guardsNames = Console.ReadLine().Split(); var footmenNames = Console.ReadLine().Split(); foreach (var name in guardsNames) { var royalGuard = new RoyalGuard(name); king.AddSoldier(royalGuard); } foreach (var name in footmenNames) { var footman = new Footman(name); king.AddSoldier(footman); } string input; while ((input = Console.ReadLine()) != "End") { var commandArgs = input.Split(); var command = commandArgs[0]; switch (command) { case "Kill": var soldierName = commandArgs[1]; var soldier = king.Soldiers.FirstOrDefault(s => s.Name == soldierName); soldier.TakeAttack(); break; case "Attack": king.OnAttack(); break; default: break; } } }
private Tantumwald() { CurrentKing = new King("Kojima I"); }
public void BeforeEachTest() { Target = new King(); MovesFrom3_3 = Target.GetMovesFrom(new BoardCoordinate(3, 3)); }
private void AddStartingPieces() { // add pawns for (int i = 0; i < RankCount; ++i) { Pawn p = CreatePiece(1, i, Color.white, "White Pawn ", typeof(Pawn)) as Pawn; p.color = Color.white; p.square = board[1, i]; board[1, i].piece = p; whitePieces.Add(p); p = CreatePiece(6, i, Color.black, "Black Pawn ", typeof(Pawn)) as Pawn; p.color = Color.black; p.square = board[6, i]; board[6, i].piece = p; blackPieces.Add(p); } // add rooks Rook r = CreatePiece(0, 0, Color.white, "White Rook ", typeof(Rook)) as Rook; r.color = Color.white; r.square = board[0, 0]; board[0, 0].piece = r; whitePieces.Add(r); r = CreatePiece(0, 7, Color.white, "White Rook ", typeof(Rook)) as Rook; r.color = Color.white; r.square = board[0, 7]; board[0, 7].piece = r; whitePieces.Add(r); r = CreatePiece(7, 0, Color.black, "Black Rook ", typeof(Rook)) as Rook; r.color = Color.black; r.square = board[7, 0]; board[7, 0].piece = r; blackPieces.Add(r); r = CreatePiece(7, 7, Color.black, "Black Rook ", typeof(Rook)) as Rook; r.color = Color.black; r.square = board[7, 7]; board[7, 7].piece = r; blackPieces.Add(r); // add knights Knight n = CreatePiece(0, 1, Color.white, "White Knight ", typeof(Knight)) as Knight; n.color = Color.white; n.square = board[0, 1]; board[0, 1].piece = n; whitePieces.Add(n); n = CreatePiece(0, 6, Color.white, "White Knight ", typeof(Knight)) as Knight; n.color = Color.white; n.square = board[0, 6]; board[0, 6].piece = n; whitePieces.Add(n); n = CreatePiece(7, 1, Color.black, "Black Knight ", typeof(Knight)) as Knight; n.color = Color.black; n.square = board[7, 1]; board[7, 1].piece = n; blackPieces.Add(n); n = CreatePiece(7, 6, Color.black, "Black Knight ", typeof(Knight)) as Knight; n.color = Color.black; n.square = board[7, 6]; board[7, 6].piece = n; blackPieces.Add(n); // add bishops Bishop b = CreatePiece(0, 2, Color.white, "White Bishop ", typeof(Bishop)) as Bishop; b.color = Color.white; b.square = board[0, 2]; board[0, 2].piece = b; whitePieces.Add(b); b = CreatePiece(0, 5, Color.white, "White Bishop ", typeof(Bishop)) as Bishop; b.color = Color.white; b.square = board[0, 5]; board[0, 5].piece = b; whitePieces.Add(b); b = CreatePiece(7, 2, Color.black, "Black Bishop ", typeof(Bishop)) as Bishop; b.color = Color.black; b.square = board[7, 2]; board[7, 2].piece = b; blackPieces.Add(b); b = CreatePiece(7, 5, Color.black, "Black Bishop ", typeof(Bishop)) as Bishop; b.color = Color.black; b.square = board[7, 5]; board[7, 5].piece = b; blackPieces.Add(b); // add kings King k = CreatePiece(0, 4, Color.white, "White King ", typeof(King)) as King; k.color = Color.white; k.square = board[0, 4]; board[0, 4].piece = k; k = CreatePiece(7, 4, Color.black, "Black King ", typeof(King)) as King; k.color = Color.black; k.square = board[7, 4]; board[7, 4].piece = k; // add queens Queen q = CreatePiece(0, 3, Color.white, "White Queen ", typeof(Queen)) as Queen; q.color = Color.white; q.square = board[0, 3]; board[0, 3].piece = q; whitePieces.Add(q); q = CreatePiece(7, 3, Color.black, "Black Queen ", typeof(Queen)) as Queen; q.color = Color.black; q.square = board[7, 3]; board[7, 3].piece = q; blackPieces.Add(q); }
public void SetNewPawnPosition_ValidPosition() { Pawn firstPawn = new Pawn('A', new string[] { "ADL", "ADR" }, new int[] { 2, 4 }); Pawn secondPawn = new Pawn('B', new string[] { "BDL", "BDR" }, new int[] { 2, 8 }); Pawn thirdPawn = new Pawn('C', new string[] { "CDL", "CDR" }, new int[] { 2, 12 }); Pawn fourthPawn = new Pawn('D', new string[] { "DDL", "DDR" }, new int[] { 9, 16 }); King theKing = new King(); GameBoard gameBoard = new GameBoard(); GameEngine myTestEngine = new GameEngine(gameBoard, firstPawn, secondPawn, thirdPawn, fourthPawn, theKing); myTestEngine.InitGame(); Assert.IsTrue(myTestEngine.SetNewPawnPosition("ADR")); }
public void SetNewKingPostion_UpRightMove() { Pawn firstPawn = new Pawn('A', new string[] { "ADL", "ADR" }, new int[] { 2, 4 }); Pawn secondPawn = new Pawn('B', new string[] { "BDL", "BDR" }, new int[] { 2, 8 }); Pawn thirdPawn = new Pawn('C', new string[] { "CDL", "CDR" }, new int[] { 2, 12 }); Pawn fourthPawn = new Pawn('D', new string[] { "DDL", "DDR" }, new int[] { 9, 16 }); King theKing = new King(); GameBoard gameBoard = new GameBoard(); GameEngine myTestEngine = new GameEngine(gameBoard, firstPawn, secondPawn, thirdPawn, fourthPawn, theKing); myTestEngine.InitGame(); int[] expectedCoords = new int[] { 8, 12 }; myTestEngine.SetNewKingPosition("KUR"); CollectionAssert.AreEqual(expectedCoords, theKing.FigurePosition); }
public static bool ChessValidator(FigurePositions currentPositions) { bool hasCheck = false; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { Names currentFigureName = currentPositions.Position[i, j].Name; if (currentFigureName == Names.None) { continue; } Colors currentFigureColors = currentPositions.Position[i, j].Color; Player currentPlayer; if (currentFigureColors == Colors.White) { currentPlayer = StartProgram.WhitePlayer; } else { currentPlayer = StartProgram.BlackPlayer; } if (currentFigureName == Names.Pawn) { Pawn pawn = new Pawn(currentFigureColors, currentFigureName); hasCheck = pawn.MakesChess(i, j, currentPlayer, currentPositions); } else if (currentFigureName == Names.Bishop) { Bishop bishop = new Bishop(currentFigureColors, currentFigureName); hasCheck = bishop.MakesChess(i, j, currentPlayer, currentPositions); } else if (currentFigureName == Names.Rook) { Rook rook = new Rook(currentFigureColors, currentFigureName); hasCheck = rook.MakesChess(i, j, currentPlayer, currentPositions); } else if (currentFigureName == Names.Queen) { Queen queen = new Queen(currentFigureColors, currentFigureName); hasCheck = queen.MakesChess(i, j, currentPlayer, currentPositions); } else if (currentFigureName == Names.King) { King king = new King(currentFigureColors, currentFigureName); hasCheck = king.MakesChess(i, j, currentPlayer, currentPositions); } else if (currentFigureName == Names.Knight) { Knight knight = new Knight(currentFigureColors, currentFigureName); hasCheck = knight.MakesChess(i, j, currentPlayer, currentPositions); } if (hasCheck) { return(hasCheck); } } } return(hasCheck); }
private static void ReadKingData() { king = new King(Console.ReadLine()); }
static void CustomLocalGame() { Log(Environment.NewLine); Log("[1] Normal game with delay and more dum opponent"); Log("[2] Endgame. QR vs -"); Log("[3] Endgame. RR vs R"); Log("[4] Endgame. PPPP vs PPPP"); Log("[Any] Exit"); Console.Write(" > "); var input = Console.ReadKey(); if (input.KeyChar.ToString() == "1") { StartLocalGame(2000, 3); } else if (input.KeyChar.ToString() == "2") { var board = new Board(); var pieces = new List <PieceBase> { new Rook(true, "a1"), new Queen(true, "h1") }; board.AddNew(pieces); // var whiteKing = new King(true, "e1"); board.AddNew(whiteKing); var blackKing = new King(false, "e8"); board.AddNew(blackKing); board.Kings = (whiteKing, blackKing); StartLocalGame(1500, null, board); } else if (input.KeyChar.ToString() == "3") { var board = new Board(); var pieces = new List <PieceBase> { new Rook(true, "a1"), new Rook(true, "h1"), new Rook(false, "d8") }; board.AddNew(pieces); // var whiteKing = new King(true, "e1"); board.AddNew(whiteKing); var blackKing = new King(false, "e8"); board.AddNew(blackKing); board.Kings = (whiteKing, blackKing); StartLocalGame(800, null, board); } else if (input.KeyChar.ToString() == "4") { var board = new Board(); var pieces = new List <PieceBase> { new Pawn(true, "c2"), new Pawn(true, "d2"), new Pawn(true, "e2"), new Pawn(true, "f2"), new Pawn(false, "c7"), new Pawn(false, "d7"), new Pawn(false, "e7"), new Pawn(false, "f7") }; board.AddNew(pieces); // var whiteKing = new King(true, "e1"); board.AddNew(whiteKing); var blackKing = new King(false, "e8"); board.AddNew(blackKing); board.Kings = (whiteKing, blackKing); StartLocalGame(1000, null, board); } }
private List <Piece> AddPieces(bool isWhite) { List <Piece> pieces = new List <Piece>(); int colStart = isWhite ? 0 : 6; int colEnd = isWhite ? 2 : 8; for (int i = 0; i < 8; i++) { for (int j = colStart; j < colEnd; j++) { if ((isWhite && j == colStart) || (!isWhite && j != colStart)) { switch (i) { case 0: case 7: { matrix[i, j] = new Rook(isWhite, i, j, matrix); } break; case 1: case 6: { matrix[i, j] = new Knight(isWhite, i, j, matrix); } break; case 2: case 5: { matrix[i, j] = new Bishop(isWhite, i, j, matrix); } break; case 3: { matrix[i, j] = new Queen(isWhite, i, j, matrix); } break; case 4: { matrix[i, j] = new King(isWhite, i, j, matrix); if (isWhite) { whiteKing = matrix[i, j].Start; } else { blackKing = matrix[i, j].Start; } } break; } pieces.Add(matrix[i, j]); } else { matrix[i, j] = new Pawn(isWhite, i, j, matrix); pieces.Add(matrix[i, j]); } } } return(pieces); }
public ChessMoveInfo Check(Square[,] board, King from, ChessFigure to) { if (Check_for_color_match(from, to)) { return(new ChessMoveInfo(false)); } if (Check_if_king_is_check_after(board, from, to)) { //Same idea but this time we check if the move puts //the life of our dear king in danger. return(new ChessMoveInfo(false)); } ChessMoveInfo MoveInfo = new ChessMoveInfo(true, from.IsWhite); MoveInfo.FromRow = from.Row; MoveInfo.FromCol = from.Col; MoveInfo.ToRow = to.Row; MoveInfo.ToCol = to.Col; if (to.Name != "Empty") { MoveInfo.TakenFigureRow = to.Row; MoveInfo.TakenFigureCol = to.Col; } if (Math.Abs(from.Col - to.Col) == 1 && Math.Abs(from.Row - to.Row) == 1) { return(MoveInfo); } if (Math.Abs(from.Col - to.Col) == 1 && Math.Abs(from.Row - to.Row) == 0) { return(MoveInfo); } if (Math.Abs(from.Col - to.Col) == 0 && Math.Abs(from.Row - to.Row) == 1) { return(MoveInfo); } if (Constants.BoardCols == 8 && Constants.BoardRows == 8 && from.HasMoved == false) { if (from.IsWhite) { if (to.Row == 7 && to.Col == 6 && board[7, 7].Figure.Name == "Rook" && (board[7, 7].Figure as Rook).HasMoved == false && Square_is_empty(board[7, 6]) && Square_is_empty(board[7, 5])) { MoveInfo.WasKingSideCastle = true; return(MoveInfo); } if (to.Row == 7 && to.Col == 2 && board[7, 0].Figure.Name == "Rook" && (board[7, 0].Figure as Rook).HasMoved == false && Square_is_empty(board[7, 1]) && Square_is_empty(board[7, 2]) && Square_is_empty(board[7, 3])) { MoveInfo.WasQueenSideCastle = true; return(MoveInfo); } } else { if (to.Row == 0 && to.Col == 6 && board[0, 7].Figure.Name == "Rook" && (board[0, 7].Figure as Rook).HasMoved == false && Square_is_empty(board[0, 6]) && Square_is_empty(board[0, 5])) { MoveInfo.WasKingSideCastle = true; return(MoveInfo); } if (to.Row == 0 && to.Col == 2 && board[0, 0].Figure.Name == "Rook" && (board[0, 0].Figure as Rook).HasMoved == false && Square_is_empty(board[0, 1]) && Square_is_empty(board[0, 2]) && Square_is_empty(board[0, 3])) { MoveInfo.WasQueenSideCastle = true; return(MoveInfo); } } } return(new ChessMoveInfo(false)); }
public void Initialize() { Pieces = new List <Piece>(); Renderables = new List <IRenderable>(); var king = new King() { X = 4, Y = 0 }; Pieces.Add(king); var queen = new Queen() { X = 3, Y = 0 }; Pieces.Add(queen); var bishop1 = new Bishop() { X = 2, Y = 0 }; Pieces.Add(bishop1); var bishop2 = new Bishop() { X = 5, Y = 0 }; Pieces.Add(bishop2); var knight1 = new Knight() { X = 1, Y = 0 }; Pieces.Add(knight1); var knight2 = new Knight() { X = 6, Y = 0 }; Pieces.Add(knight2); var castle1 = new Castle { X = 0, Y = 0 }; Pieces.Add(castle1); var castle2 = new Castle { X = 7, Y = 0 }; Pieces.Add(castle2); var pawn1 = new Pawn() { X = 7, Y = 1 }; Pieces.Add(pawn1); var pawn2 = new Pawn() { X = 6, Y = 1 }; Pieces.Add(pawn2); var pawn3 = new Pawn() { X = 5, Y = 1 }; Pieces.Add(pawn3); var pawn4 = new Pawn() { X = 4, Y = 1 }; Pieces.Add(pawn4); var pawn5 = new Pawn() { X = 3, Y = 1 }; Pieces.Add(pawn5); var pawn6 = new Pawn() { X = 2, Y = 1 }; Pieces.Add(pawn6); var pawn7 = new Pawn() { X = 1, Y = 1 }; Pieces.Add(pawn7); var pawn8 = new Pawn() { X = 0, Y = 1 }; Pieces.Add(pawn8); foreach (var piece in Pieces) { Renderables.Add(piece); piece.Visible = true; piece.GetMoves(); } }
public void BeforeEachTest() { Target = new King(); MovesFrom_3_3 = Target.GetMovesFrom(new BoardCoordinate(3, 3)); }
public void Have_K_AsShortName() { var king = new King(Player.Black, "5i"); Assert.Equal('K', king.ShortName); }
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); } }
protected Soldier(string name, int hitsTaken, King kingToDefend) { this.Name = name; this.hitsTaken = hitsTaken; this.kingDefended = kingToDefend; }
public static bool isMate(King king, ChessPiece[,] positions) { for (int i = 0, rank = king.Rank - 1; i < 3; i++, rank++) { for (int j = 0, file = king.File - 1; j < 3; j++, file++) { if (rank < 0 || rank > 7 || file < 0 || file > 7 || rank == file) continue; if (king. isValidMove (rank, file, positions, ChessBoardConstants. MOVE_EXCHANGE)) return false; } } return true; }
public IFigure CreateFigure(FigureSign sign) { IFigure king = new King(sign); return king; }
public RoyalGuard(string name, King kingToDefend) : base(name, DefaultHits, kingToDefend) { }
public bool addPiece(ChessPiece piece) { if (color != piece.Color) return false; if (piece.Type == PieceType.KING) { king = (King) piece; return true; } IList list = getListOfType (piece.Type); if (list == null) return false; if (!list.Contains (piece)) list.Add (piece); return true; }
public void TestKingWeapon() { HeadFirstDesignPatterns.Strategy.Character.King KingWeapon = new King(); Assert.AreEqual("I swing at thee with this sword!", KingWeapon.Fight()); }
protected King(King pieceToClone) : base(pieceToClone) { }
private void Awake() { piecesKingAlpha[index] = new King(index <= 1 ? PlayerColor.White : PlayerColor.Black); piecesRookAlpha[index] = new Rook(index <= 1 ? PlayerColor.White : PlayerColor.Black); }
public int AttackedBySquare(bool sideToMove, int[] board, int squareInQuestion) { var imaginaryKnight = new Knight(board, squareInQuestion, sideToMove); var listOfAttackingSquares = imaginaryKnight.MoveGeneration(); foreach (var square in listOfAttackingSquares) { if (board[square] == Definitions.WhiteKnight || board[square] == Definitions.BlackKnight) { return(square); } } var imaginaryBishop = new Bishop(board, squareInQuestion, sideToMove); var listOfBishopMoves = imaginaryBishop.MoveGeneration(); foreach (var possibleAttackedFromSquare in listOfBishopMoves) { if (board[possibleAttackedFromSquare] == Definitions.WhiteQueen || board[possibleAttackedFromSquare] == Definitions.BlackQueen || board[possibleAttackedFromSquare] == Definitions.WhiteBishop || board[possibleAttackedFromSquare] == Definitions.BlackBishop) { return(possibleAttackedFromSquare); } } var imaginaryKing = new King(board, squareInQuestion, sideToMove); var listOfKingMoves = imaginaryKing.MoveGeneration(); foreach (var possibleAttackedFromSquare in listOfKingMoves) { if (board[possibleAttackedFromSquare] == Definitions.WhiteKing || board[possibleAttackedFromSquare] == Definitions.BlackKing) { return(possibleAttackedFromSquare); } } if (sideToMove == Definitions.WhiteToMove) { // Check if black has pawns that can attack us. if (board[squareInQuestion + 11] == Definitions.BlackPawn) { return(squareInQuestion + 11); } if (board[squareInQuestion + 9] == Definitions.BlackPawn) { return(squareInQuestion + 9); } } else { // Check if white has pawns that can attack us. if (board[squareInQuestion - 11] == Definitions.WhitePawn) { return(squareInQuestion - 11); } if (board[squareInQuestion - 9] == Definitions.WhitePawn) { return(squareInQuestion - 9); } } var imaginaryRook = new Rook(board, squareInQuestion, sideToMove); var listOfRookMoves = imaginaryRook.MoveGeneration(); foreach (var possibleAttackedFromSquares in listOfRookMoves) { if (board[possibleAttackedFromSquares] == Definitions.WhiteQueen || board[possibleAttackedFromSquares] == Definitions.BlackQueen || board[possibleAttackedFromSquares] == Definitions.WhiteRook || board[possibleAttackedFromSquares] == Definitions.BlackRook) { return(possibleAttackedFromSquares); } } return(99); }
public DoubleChess() : base(BOARD_WIDTH, BOARD_HEIGHT) { secondCurrentKing = secondOpposingKing = null; }
public void Constructor_PassedValidData_GivesAProperName() { IChessPiece king = new King(1, 1, 1); Assert.Equal("King", king.Name); }
public void showPossible(Piece[,] board, int sx, int sy) { var showPossibleSpots = new Player(3); showPossibleSpots.PlayerColor = ConsoleColor.Green; var kingShow = new King(showPossibleSpots); kingShow.name = "o"; //temporarily set the value of the pieces at the spots to the new symbol if (sx - 1 >= 0) { if (board[sy, sx - 1] == null) { board[sy, sx - 1] = kingShow; } else if (board[sy, sx - 1].getPlayer() != Game.player) { board[sy, sx - 1].setPlayerNumber(3); } if (sy - 1 >= 0) { if (board[sy - 1, sx - 1] == null) { board[sy - 1, sx - 1] = kingShow; } else if (board[sy - 1, sx - 1].getPlayer() != Game.player) { board[sy - 1, sx - 1].setPlayerNumber(3); } } if (sy + 1 <= 7) { if (board[sy + 1, sx - 1] == null) { board[sy + 1, sx - 1] = kingShow; } else if (board[sy + 1, sx - 1].getPlayer() != Game.player) { board[sy + 1, sx - 1].setPlayerNumber(3); } } } if (sx + 1 <= 7) { if (board[sy, sx + 1] == null) { board[sy, sx + 1] = kingShow; } else if (board[sy, sx + 1].getPlayer() != Game.player) { board[sy, sx + 1].setPlayerNumber(3); } if (sy - 1 >= 0) { if (board[sy - 1, sx + 1] == null) { board[sy - 1, sx + 1] = kingShow; } else if (board[sy - 1, sx + 1].getPlayer() != Game.player) { board[sy - 1, sx + 1].setPlayerNumber(3); } } if (sy + 1 <= 7) { if (board[sy + 1, sx + 1] == null) { board[sy + 1, sx + 1] = kingShow; } else if (board[sy + 1, sx + 1].getPlayer() != Game.player) { board[sy + 1, sx + 1].setPlayerNumber(3); } } } if (sy - 1 >= 0) { if (board[sy - 1, sx] == null) { board[sy - 1, sx] = kingShow; } else if (board[sy - 1, sx].getPlayer() != Game.player) { board[sy - 1, sx].setPlayerNumber(3); } } if (sy + 1 <= 7) { if (board[sy + 1, sx] == null) { board[sy + 1, sx] = kingShow; } else if (board[sy + 1, sx].getPlayer() != Game.player) { board[sy + 1, sx].setPlayerNumber(3); } } //now reset the values to null since we are done }
private bool CanAttackerBeBlocked(Square[,] board, List <Square> attackingPath, King attackedKing) { bool canBeBlocked = false; foreach (var boardSquare in board) { if (boardSquare.Figure.Name != Constants.EmptySquare) { if (boardSquare.Figure.IsWhite == attackedKing.IsWhite && boardSquare.Figure.Name != Constants.KingName) { foreach (var attackingPathSquare in attackingPath) { if (rulesService.Check(board, boardSquare.Figure, attackingPathSquare.Figure)) { return(true); } } } } } return(canBeBlocked); }
protected override void ChargeItem(King king, int count) { king.CollectDiamond(count); }
public Board() { for (int Row = 0; Row < 8; Row++) { for (int Col = 0; Col < 16; Col++) { board[Row, Col] = null; } } // black inner pawns for (int Row = 0; Row < 8; Row++) { board[Row, 10] = new InnerPawn('b'); } // black outer pawns for (int Row = 0; Row < 8; Row++) { board[Row, 13] = new OuterPawn('b'); } //black pieces board[0, 11] = new Rook('b'); board[0, 12] = new Rook('b'); board[7, 11] = new Rook('b'); board[7, 12] = new Rook('b'); board[1, 11] = new Knight('b'); board[1, 12] = new Knight('b'); board[6, 11] = new Knight('b'); board[6, 12] = new Knight('b'); board[2, 11] = new Bishop('b'); board[2, 12] = new Bishop('b'); board[5, 11] = new Bishop('b'); board[5, 12] = new Bishop('b'); board[3, 12] = new Queen('b'); board[4, 12] = new Queen('b'); board[3, 11] = new General('b'); board[4, 11] = new King('b'); // white inner pawns for (int Row = 0; Row < 8; Row++) { board[Row, 5] = new InnerPawn('w'); } // white outer pawns for (int Row = 0; Row < 8; Row++) { board[Row, 2] = new OuterPawn('w'); } //white pieces board[0, 3] = new Rook('w'); board[0, 4] = new Rook('w'); board[7, 3] = new Rook('w'); board[7, 4] = new Rook('w'); board[1, 3] = new Knight('w'); board[1, 4] = new Knight('w'); board[6, 3] = new Knight('w'); board[6, 4] = new Knight('w'); board[2, 3] = new Bishop('w'); board[2, 4] = new Bishop('w'); board[5, 3] = new Bishop('w'); board[5, 4] = new Bishop('w'); board[3, 3] = new Queen('w'); board[4, 3] = new Queen('w'); board[3, 4] = new General('w'); board[4, 4] = new King('w'); }