private static void SetMovesWhitePawn() { for (byte index = 8; index <= 55; index++) { PieceMoveSet moveset = new PieceMoveSet(new List <byte> ()); byte x = (byte)(index % 8); byte y = (byte)(index / 8); // Diagonal: can move if capturing if (x < 7 && y > 0) { moveset.Moves.Add((byte)(index - 8 + 1)); } if (x > 0 && y > 0) { moveset.Moves.Add((byte)(index - 8 - 1)); } // Move one space forward moveset.Moves.Add((byte)(index - 8)); // If the pawn is in its starting position, it can jump 2 if (y == 6) { moveset.Moves.Add((byte)(index - 16)); } MoveArrays.WhitePawnMoves [index] = moveset; } }
private static void SetMovesKing() { for (byte y = 0; y < 8; y++) { for (byte x = 0; x < 8; x++) { byte index = (byte)(y + (x * 8)); PieceMoveSet moveset = new PieceMoveSet(new List <byte> ()); byte move; byte row = x; byte col = y; // South if (row < 7) { row++; move = Position(col, row); moveset.Moves.Add(move); } row = x; col = y; // North if (row > 0) { row--; move = Position(col, row); moveset.Moves.Add(move); } row = x; col = y; // West if (col > 0) { col--; move = Position(col, row); moveset.Moves.Add(move); } row = x; col = y; // East if (col < 7) { col++; move = Position(col, row); moveset.Moves.Add(move); } row = x; col = y; // Southeast if (row < 7 && col < 7) { row++; col++; move = Position(col, row); moveset.Moves.Add(move); } row = x; col = y; // Southwest if (row < 7 && col > 0) { row++; col--; move = Position(col, row); moveset.Moves.Add(move); } row = x; col = y; // Northeast if (row > 0 && col < 7) { row--; col++; move = Position(col, row); moveset.Moves.Add(move); } row = x; col = y; // Northwest if (row > 0 && col > 0) { row--; col--; move = Position(col, row); moveset.Moves.Add(move); } MoveArrays.KingMoves [index] = moveset; } } }
private static void SetMovesRook() { for (byte y = 0; y < 8; y++) { for (byte x = 0; x < 8; x++) { byte index = (byte)(y + (x * 8)); PieceMoveSet moveset = new PieceMoveSet(new List <byte> ()); byte move; byte row = x; byte col = y; // South while (row < 7) { row++; move = Position(col, row); moveset.Moves.Add(move); } MoveArrays.RookMoves1 [index] = moveset; moveset = new PieceMoveSet(new List <byte> ()); row = x; col = y; // North while (row > 0) { row--; move = Position(col, row); moveset.Moves.Add(move); } MoveArrays.RookMoves2 [index] = moveset; moveset = new PieceMoveSet(new List <byte> ()); row = x; col = y; // West while (col > 0) { col--; move = Position(col, row); moveset.Moves.Add(move); } MoveArrays.RookMoves3 [index] = moveset; moveset = new PieceMoveSet(new List <byte> ()); row = x; col = y; // East while (col < 7) { col++; move = Position(col, row); moveset.Moves.Add(move); } MoveArrays.RookMoves4 [index] = moveset; moveset = new PieceMoveSet(new List <byte> ()); } } }
private static void SetMovesBishop() { for (byte y = 0; y < 8; y++) { for (byte x = 0; x < 8; x++) { byte index = (byte)(y + (x * 8)); PieceMoveSet moveset = new PieceMoveSet(new List <byte> ()); byte move; byte row = x; byte col = y; // Diagonally southeast while (row < 7 && col < 7) { row++; col++; move = Position(col, row); moveset.Moves.Add(move); } MoveArrays.BishopMoves1 [index] = moveset; moveset = new PieceMoveSet(new List <byte> ()); row = x; col = y; // Diagonally southwest while (row < 7 && col > 0) { row++; col--; move = Position(col, row); moveset.Moves.Add(move); } MoveArrays.BishopMoves2 [index] = moveset; moveset = new PieceMoveSet(new List <byte> ()); row = x; col = y; // Diagonally northeast while (row > 0 && col < 7) { row--; col++; move = Position(col, row); moveset.Moves.Add(move); } MoveArrays.BishopMoves3 [index] = moveset; moveset = new PieceMoveSet(new List <byte> ()); row = x; col = y; // Diagonally northwest while (row > 0 && col > 0) { row--; col--; move = Position(col, row); moveset.Moves.Add(move); } MoveArrays.BishopMoves4 [index] = moveset; } } }
private static void SetMovesKnight() { for (byte y = 0; y < 8; y++) { for (byte x = 0; x < 8; x++) { byte index = (byte)(y + (x * 8)); PieceMoveSet moveset = new PieceMoveSet(new List <byte> ()); byte move; if (y < 6 && x > 0) { move = Position((byte)(y + 2), (byte)(x - 1)); if (move < 64) { moveset.Moves.Add(move); } } if (y > 1 && x < 7) { move = Position((byte)(y - 2), (byte)(x + 1)); if (move < 64) { moveset.Moves.Add(move); } } if (y > 1 && x > 0) { move = Position((byte)(y - 2), (byte)(x - 1)); if (move < 64) { moveset.Moves.Add(move); } } if (y < 6 && x < 7) { move = Position((byte)(y + 2), (byte)(x + 1)); if (move < 64) { moveset.Moves.Add(move); } } if (y > 0 && x < 6) { move = Position((byte)(y - 1), (byte)(x + 2)); if (move < 64) { moveset.Moves.Add(move); } } if (y < 7 && x > 1) { move = Position((byte)(y + 1), (byte)(x - 2)); if (move < 64) { moveset.Moves.Add(move); } } if (y > 0 && x > 1) { move = Position((byte)(y - 1), (byte)(x - 2)); if (move < 64) { moveset.Moves.Add(move); } } if (y < 7 && x < 6) { move = Position((byte)(y + 1), (byte)(x + 2)); if (move < 64) { moveset.Moves.Add(move); } } MoveArrays.KnightMoves [index] = moveset; } } }