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 void BeforeEachTest() { Piece = new Pawn(); Target = new Board(); Target.AddPiece(Piece, new BoardCoordinate(1, 1)); }
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 void BeforeEachTest() { Target = new Pawn(); MovesFrom22 = Target.GetMovesFrom(new BoardCoordinate(2, 2)); }
public FormPromotion(Pawn p) { InitializeComponent(); this.pawn = p; }
/********************************************************************* * 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); }
public override List <byte[][]> GetMove(Piece[,] board) { List <byte[][]> moves = new List <byte[][]>(); byte[] pos = GetPos(board); sbyte sign = (sbyte)((((team + 1) % 2) * 2) - 1); sbyte[] vec = { (sbyte)(sign * (team / 2)), (sbyte)((((team / 2) + 1) % 2) * sign) }; // Move one, then two for (int i = 1; i < 3; i++) { if (i == 2 && hasMoved) { continue; } byte[] tempPos = { (byte)(pos[0] + (vec[0] * i)), (byte)(pos[1] + (vec[1] * i)) }; if (0 <= tempPos[0] && tempPos[0] < board.GetLength(0) && 0 <= tempPos[1] && tempPos[1] < board.GetLength(1)) { if (board[tempPos[0], tempPos[1]] == null) { byte[][] move = new byte[2][]; move[0] = new byte[] { tempPos[0], tempPos[1], pos[0], pos[1] }; move[1] = new byte[] { pos[0], pos[1], byte.MaxValue, (byte)(byte.MaxValue - i) }; moves.Add(move); } else { break; } } } // Check if can capture for (int i = -1; i < 2; i += 2) { byte[] tempPos = { (byte)(pos[0] + vec[0]), (byte)(pos[1] + vec[1]) }; tempPos[0] += (byte)(((vec[0] + 1) % 2) * i); tempPos[1] += (byte)(((vec[1] + 1) % 2) * i); if (0 <= tempPos[0] && tempPos[0] < board.GetLength(0) && 0 <= tempPos[1] && tempPos[1] < board.GetLength(1)) { if (board[tempPos[0], tempPos[1]] != null) { if (board[tempPos[0], tempPos[1]].team != this.team) { byte[][] move = new byte[3][]; move[0] = new byte[] { tempPos[0], tempPos[1], byte.MaxValue, byte.MaxValue }; move[1] = new byte[] { tempPos[0], tempPos[1], pos[0], pos[1] }; move[2] = new byte[] { pos[0], pos[1], byte.MaxValue, byte.MaxValue - 1 }; moves.Add(move); } } } } // Check for En Passant for (int i = -1; i < 2; i += 2) { byte[] tempPos = { (byte)(pos[0]), (byte)(pos[1]) }; tempPos[0] += (byte)(((vec[0] + 1) % 2) * i); tempPos[1] += (byte)(((vec[1] + 1) % 2) * i); if (0 <= tempPos[0] && tempPos[0] < board.GetLength(0) && 0 <= tempPos[0] && tempPos[0] < board.GetLength(1)) { if (board[tempPos[0], tempPos[1]] != null) { if (board[tempPos[0], tempPos[1]].team != this.team) { if (board[tempPos[0], tempPos[1]].GetType().IsSubclassOf(typeof(Pawn)) || board[tempPos[0], tempPos[1]].GetType() == typeof(Pawn)) { Pawn p = (Pawn)board[tempPos[0], tempPos[1]]; if (p.movedTwice) { byte[][] move = new byte[3][]; move[0] = new byte[] { tempPos[0], tempPos[1], byte.MaxValue, byte.MaxValue }; tempPos[0] = (byte)(tempPos[0] + vec[0]); tempPos[1] = (byte)(tempPos[1] + vec[1]); if (board[tempPos[0], tempPos[1]] != null) { continue; } move[1] = new byte[] { tempPos[0], tempPos[1], pos[0], pos[1] }; move[2] = new byte[] { pos[0], pos[1], byte.MaxValue, byte.MaxValue - 1 }; moves.Add(move); } } } } } } return(moves); }