void rookThreatenHighlight(Piece.Colour colour, int row, int col, List<int[]> threatened, Piece[,] board) { int i = 1; //check down while (addThreatened(colour, row, col, i, 0, threatened)) { if (board[row + i, col].Exists) break; i++; } //check up i = 1; while (addThreatened(colour, row, col, -i, 0, threatened)) { if (board[row - i, col].Exists) break; i++; } //check right i = 1; while (addThreatened(colour, row, col, 0, i, threatened)) { if (board[row, col + i].Exists) break; i++; } //check left i = 1; while (addThreatened(colour, row, col, 0, -i, threatened)) { if (board[row, col - i].Exists) break; i++; } }
BitboardLayer[] pieceLocations; //0 is white, 1 is black #endregion Fields #region Constructors public AttackedSquaresGetter(ChessBoard c) { lastUpdated = new int[64]; this.c = c; pieceLocations = new BitboardLayer[2]; currAttackedSquares = new BitboardLayer[2][]; kingAttackedSquares = new BitboardLayer[2]; allAttackedSq = new BitboardLayer[2]; allValidMoves = new BitboardLayer[2]; currValidMoves = new BitboardLayer[2][]; currPinnedPcs = new List<int[]>[2]; currCheckers = new List<int[]>[2]; canCastle = new bool[2][]; for (int i = 0; i < 2; i++) { pieceLocations[i] = new BitboardLayer(); currAttackedSquares[i] = new BitboardLayer[64]; kingAttackedSquares[i] = new BitboardLayer(); currValidMoves[i] = new BitboardLayer[64]; allValidMoves[i] = new BitboardLayer(); allAttackedSq[i] = new BitboardLayer(); currPinnedPcs[i] = new List<int[]>(); canCastle[i] = new bool[] { false, false }; currCheckers[i] = new List<int[]>(); for (int j = 0; j < 64; j++) { currAttackedSquares[i][j] = new BitboardLayer(); currValidMoves[i][j] = new BitboardLayer(); } } numIterations = 0; updatePosition(true, new int[] { 63, 63 }); updatePosition(false, new int[] { 0, 0 }); }
void bishopThreatenHighlight(string colour, int row, int col, List<int[]> threatened, Piece[,] board) { int i = 1; //check down right while (addThreatened(colour, row, col, i, i, threatened)) { if (board[row + i, col + i].Exists) break; i++; } //check up right i = 1; while (addThreatened(colour, row, col, -i, i, threatened)) { if (board[row - i, col + i].Exists) break; i++; } //check up left i = 1; while (addThreatened(colour, row, col, -i, -i, threatened)) { if (board[row - i, col - i].Exists) break; i++; } //check down left i = 1; while (addThreatened(colour, row, col, i, -i, threatened)) { if (board[row + i, col - i].Exists) break; i++; } }
void pawnThreatenHighlight(Piece piece, int row, int col, List<int[]> threatened, Piece[,] board, List<int[]> enPassant) { //capturing if (piece.PieceColour == Piece.Colour.Black) { addThreatened(piece.PieceColour, piece.Row, piece.Col, 1, 1, threatened); addThreatened(piece.PieceColour, piece.Row, piece.Col, 1, -1, threatened); } if (piece.PieceColour == Piece.Colour.White) { addThreatened(piece.PieceColour, piece.Row, piece.Col, -1, 1, threatened); addThreatened(piece.PieceColour, piece.Row, piece.Col, -1, -1, threatened); } //en passant if (piece.PieceColour == Piece.Colour.Black) { addEnPassant(piece.PieceColour, piece.Row, piece.Col, 1, 1, enPassant, board); addEnPassant(piece.PieceColour, piece.Row, piece.Col, 1, -1, enPassant, board); } if (piece.PieceColour == Piece.Colour.White) { addEnPassant(piece.PieceColour, piece.Row, piece.Col, -1, 1, enPassant, board); addEnPassant(piece.PieceColour, piece.Row, piece.Col, -1, -1, enPassant, board); } }
public List<KomaBase> KomaCreate() { if (komaList != null) { return komaList; } komaList = new List<KomaBase>(); foreach (KomaKind komaKind in Enum.GetValues(typeof(KomaKind))) { int index = 0; while(true) { var komaKuro = createKoma(komaKind, PlayerNo.Two, index); komaKuro.SetDefaultPoint(); var komaShiro = createKoma(komaKind, PlayerNo.One, index); komaShiro.SetDefaultPoint(); komaList.AddRange(new[] { komaKuro, komaShiro }); if (komaShiro.GetMaxCount() == index + 1) break; ++index; } } return komaList; }
//create new board public Board() { //Initiate Pawns for (int i = 0; i < 8; i++) { WhitePieces.Add(new Pawn(true, this)); BlackPieces.Add(new Pawn(false, this)); } //Initiate Knights/Bishops/Rooks for (int i = 0; i < 2; i++) { WhitePieces.Add(new Knight(true, this)); BlackPieces.Add(new Knight(false, this)); WhitePieces.Add(new Bishop(true, this)); BlackPieces.Add(new Bishop(false, this)); WhitePieces.Add(new Rook(true, this)); BlackPieces.Add(new Rook(false, this)); } //Intiate Kings/Queens WhitePieces.Add(new King(true, this)); WhitePieces.Add(new Queen(true, this)); BlackPieces.Add(new Queen(false, this)); BlackPieces.Add(new King(false, this)); AllPieces = WhitePieces; AllPieces.AddRange(BlackPieces); }
public bool isThreatened(int row, int col, Piece.Colour threatenedBy, Piece[,] board) { bool threatened = false; List<int[]> covered = new List<int[]>(); List<int[]> filler = new List<int[]>(); for (int rows = 0; rows < Board.Rows; rows++) { for (int cols = 0; cols < Board.Cols; cols++) { if (board[rows, cols].PieceColour == threatenedBy) { thm.highlightThreatened(board[rows, cols], rows, cols, covered, filler, board, false); } } } foreach (int[] pair in covered) { if (pair[0] == row && pair[1] == col) { threatened = true; break; } } return threatened; }
public List<Tuple<int, int>> Rules(Piece currentPiece, Gameboard gameboard) { this.moves_dia = get_diagonal.Rules(currentPiece, gameboard); this.moves_str = get_straight.Rules(currentPiece, gameboard); moves_str = moves_str.Concat(moves_dia).ToList(); return moves_str; }
void addEnPassant(string colour, int row, int col, int rowOffset, int colOffset, List<int[]> enPassant, Piece[,] board) { int destinationRow = row + rowOffset; int destinationCol = col + colOffset; if (destinationRow >= 0 && destinationRow <= 7 && destinationCol >= 0 && destinationCol <= 7 && board[row, col + colOffset].EnPassant) { enPassant.Add(new int[] { destinationRow, destinationCol }); } }
public override List<Tuple<MoveType, int, int>> GetMovableLoacation() { int h = Player == PlayerNo.Two ? -1 : 1; var list = new List<Tuple<MoveType, int, int>>(); list.Add(new Tuple<MoveType, int, int>(MoveType.NotExistAny, Left, Height+h)); list.Add(new Tuple<MoveType, int, int>(MoveType.ExistsEnemy, Left - 1, Height + h)); list.Add(new Tuple<MoveType, int, int>(MoveType.ExistsEnemy, Left + 1, Height + h)); return list; }
private coord tileSize; // Size of tile #endregion Fields #region Constructors // Constructor public SidebarWidget(List<Figure> removedFigures, string color, int scale) { this.removedFigures = removedFigures; this.color = color; // Color of the sidebar's admitted figures updateSidebar (); this.WidthRequest = 5 * scale; this.tileSize = new coord (5 * scale, 5 * scale); }
internal static List<Peice> getPeices(Peice[,] board, PSide side) { List<Peice> sideList = new List<Peice>(); foreach (Peice peice in board) { if (peice != null && peice.MySide == side) { sideList.Add(peice); } } return sideList; }
bool addThreatened(string colour, int row, int col, int rowOffset, int colOffset, List<int[]> threatened) { bool added = false; int destinationRow = row + rowOffset; int destinationCol = col + colOffset; if (uf.IsInBounds(destinationRow, destinationCol)) { threatened.Add(new int[] { destinationRow, destinationCol }); added = true; } return added; }
//doenst include king public List<Pair> GetBlackPosistions() { List<Pair> Positions = new List<Pair>(); foreach (ChessPiece piece in WhitePieces) { if (piece.InPlay) { Positions.Add(piece.Position); } } return Positions; }
public void InitializePlayfield(ref bool isWhiteTurn, ref bool isGameDone, List<int[]> highlight, Piece[,] playfield, Piece[,] whiteTaken, Piece[,] blackTaken, ref int[] whiteTakenIndeces, ref int[] blackTakenIndeces) { //reseting parameters df.Clear(); isWhiteTurn = true; isGameDone = false; highlight.Clear(); whiteTakenIndeces = new int[] { 0, 0 }; blackTakenIndeces = new int[] { 0, 0 }; for (int row = 0; row < Board.Rows; row++) { for (int col = 0; col < Board.Cols; col++) { //set piece type playfield[row, col] = new Piece() { Row = row, Col = col }; if (row == Board.FirstRow || row == Board.LastRow) { if (col == Board.FirstCol || col == Board.LastCol) playfield[row, col].PieceType = Piece.Type.Rook; if (col == Board.FirstCol + 1 || col == Board.LastCol - 1) playfield[row, col].PieceType = Piece.Type.Knight; if (col == Board.FirstCol + 2 || col == Board.LastCol - 2) playfield[row, col].PieceType = Piece.Type.Bishop; if (col == Board.FirstCol + 3) playfield[row, col].PieceType = Piece.Type.Queen; if (col == Board.FirstCol + 4) playfield[row, col].PieceType = Piece.Type.King; } if (row == Board.FirstRow + 1 || row == Board.LastRow - 1) playfield[row, col].PieceType = Piece.Type.Pawn; //set piece color //all pieces in the top two rows are black if (row <= Board.FirstRow + 1) playfield[row, col].PieceColour = Piece.Colour.Black; //all pieces in the bottom two rows are white if (row >= Board.LastRow - 1) playfield[row, col].PieceColour = Piece.Colour.White; //set those pieces to existing if (row <= Board.FirstRow + 1 || row >= Board.LastRow - 1) playfield[row, col].Exists = true; } //Reset the taken grids for (int col = 0; col < 2; col++) { whiteTaken[row, col] = new Piece(); blackTaken[row, col] = new Piece(); } } }
public override List<Tuple<MoveType, int, int>> GetMovableLoacation() { var list = new List<Tuple<MoveType, int, int>>(); foreach (var l in new[] { -2,-1, 1,2 }) { foreach (var h in new[] { -2, -1, 1, 2 }) { if (l != h && h+l != 0) list.Add(new Tuple<MoveType, int, int>(MoveType.Normal, Left + l, Height + h)); } } return list; }
public override List<Tuple<MoveType, int, int>> GetMovableLoacation() { var list = new List<Tuple<MoveType, int, int>>(); foreach (int l in new[] { -1, 1 }) { foreach (int h in new[] { -1, 1 }) { list.Add(new Tuple<MoveType, int, int>(MoveType.Direction, l+this.Left, h+this.Height)); } } return list; }
public ChessBoard(ChessBoard c) { for (int i = 0; i <= pieceIndex.FLAGS; i++) { white[i] = new BitboardLayer(c.getDict(true)[i]); black[i] = new BitboardLayer(c.getDict(false)[i]); } white_ep = c.getEP(true); black_ep = c.getEP(false); moveList = new List<int[]>(c.getMoveList()); moveNum = c.getMoveNum(); ASG = c.getASG(); }
public override List<Tuple<MoveType, int, int>> GetMovableLoacation() { var list = new List<Tuple<MoveType, int, int>>(); foreach (var l in new[] { -1, 0, 1 }) { foreach (var h in new[] { -1, 0, 1 }) { if (h != 0 || l != 0) list.Add(new Tuple<MoveType, int, int>(MoveType.Direction, Left + l, Height + h)); } } return list; }
/// <summary> /// Standard Constructor. Initializes AllCells, CellLinkStrategyList, History and GraveYard /// </summary> public Board() { AllCells = new List<CellViewModel>(64); CellLinkStrategyList = new List<ICellLinkStrategy> { new DefaultCellLinkStrategy() }; History = new ObservableCollection<HistoryViewModel>(); _graveYard = new ObservableCollection<IChessPiece>(); }
public void SelectOrMove(int row, int col, List<int[]> moveable, List<int[]> threatened, List<int[]> enPassant, ref bool promote, ref bool moved) { bool doSelect = true; //enforce turn order for move if ((WhiteTurn && selectedPiece.Colour == white) || (!WhiteTurn && selectedPiece.Colour == black)) foreach (int[] pair in Highlight) if (pair[0] == row && pair[1] == col) { move(row, col, ref promote, ref doSelect, ref moved); break; } if (doSelect) select(row, col, moveable, threatened, enPassant); }
private List<Tuple< int, int>> getCanMove( IEnumerable<Tuple<MoveType, int, int>> locateInfos, KomaBase koma) { var inBoardLocates = this.getInBoardLocate(locateInfos); var canMoveLocates = new List<Tuple< int, int>>(); canMoveLocates.AddRange(this.getNotExistsAny(inBoardLocates)); canMoveLocates.AddRange(this.getExistsEnemy(inBoardLocates)); canMoveLocates.AddRange(this.getDirection(inBoardLocates, koma)); canMoveLocates.AddRange(this.getNormal(inBoardLocates)); return canMoveLocates; }
bool addMoveable(int row, int col, int rowOffset, int colOffset, List<int[]> moveable, Piece[,] board) { bool added = false; int destinationRow = row + rowOffset; int destinationCol = col + colOffset; if (uf.IsInBounds(destinationRow, destinationCol)) { if (board[destinationRow, destinationCol].Colour != board[row, col].Colour && !cf.createCheck(row, col, destinationRow, destinationCol, board)) { moveable.Add(new int[] { destinationRow, destinationCol }); added = true; } } return added; }
void pawnMoveHighlight(Piece piece, int row, int col, List<int[]> moveable, Piece[,] board) { //moving if (piece.PieceColour == Piece.Colour.Black && !board[row + 1, col].Exists) { addMoveable(piece.Row, piece.Col, 1, 0, moveable, board); if (!piece.HasMoved && !board[piece.Row + 2, piece.Col].Exists) addMoveable(piece.Row, piece.Col, 2, 0, moveable, board); } if (piece.PieceColour == Piece.Colour.White && !board[row - 1, col].Exists) { addMoveable(piece.Row, piece.Col, -1, 0, moveable, board); if (!piece.HasMoved && !board[piece.Row - 2, piece.Col].Exists) addMoveable(piece.Row, piece.Col, -2, 0, moveable, board); } }
private void cleanUp() { Gameboard copyOfGameboard = new Gameboard(gameboard); Rulebook rulebook = new Rulebook(); List<Tuple<int, int>> copyOfValids = new List<Tuple<int, int>>(); bool foundIllegalMove = false; Piece originalCurrentPiece; int currentTeam = copyOfCurrentPiece.team; int opponentTeam = info.getOpponent(currentTeam); foreach (Tuple<int, int> validMove in validDestinations) // För varje möjligt drag för markerad Piece { copyOfGameboard = new Gameboard(gameboard); originalCurrentPiece = copyOfGameboard.getPiece(copyOfCurrentPiece.row, copyOfCurrentPiece.column); Piece destination = copyOfGameboard.getPiece(validMove.Item1, validMove.Item2); copyOfGameboard.Move(originalCurrentPiece, destination); // Gör temporärt move foundIllegalMove = false; foreach (Piece opponent in copyOfGameboard.getTeam(opponentTeam)) // För varje Piece i team OPPONENT { List<Tuple<int,int>> validDest = rulebook.getValidMoves(opponent, copyOfGameboard, false); // Hämta valid moves för Piece i OPPONENT (Utan hänsyn till möjliga drag som sätter kungen i schack..) foreach (Tuple<int,int> coordinate in validDest) // För varje möjligt drag för Piece i OPPONENT { if (copyOfGameboard.getPiece(coordinate.Item1, coordinate.Item2).type == (int)type.king) // Om Piece i OPPONENT kan ta kungen i CURRENT { foundIllegalMove = true; break; } if (foundIllegalMove) break; } if (foundIllegalMove) break; } if (!foundIllegalMove) copyOfValids.Add(new Tuple<int, int>(validMove.Item1, validMove.Item2)); copyOfGameboard.setPiece(originalCurrentPiece); copyOfGameboard.setPiece(destination); } validDestinations = copyOfValids; }
public Gameboard(Gameboard originalGameboard) { for (int row = 0; row<8; ++row) { List<Piece> copyOfRow = new List<Piece>(); foreach (Piece piece in originalGameboard.getRow(row)) { Piece copyOfPiece = new Piece(piece); copyOfRow.Add(copyOfPiece); if (copyOfPiece.team == (int)team.black) this.blackTeam.Add(copyOfPiece); else if (copyOfPiece.team == (int)team.white) this.whiteTeam.Add(copyOfPiece); } this.gameboard.Add(copyOfRow); } }
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>>(); }
public void InitializePlayfield(ref bool whiteTurn, ref bool gameDone, List<int[]> highlight, Piece[,] playfield, Piece[,] whiteTaken, Piece[,] blackTaken, ref int[] whiteTakenIndeces, ref int[] blackTakenIndeces) { //reseting parameters df.Clear(); whiteTurn = true; gameDone = false; highlight.Clear(); whiteTakenIndeces = new int[] { 0, 0 }; blackTakenIndeces = new int[] { 0, 0 }; for (int row = 0; row < 8; row++) { for (int col = 0; col < 8; col++) { //set piece type playfield[row, col] = new Piece() { Row = row, Col = col }; if (row == 0 || row == 7) { if (col == 0 || col == 7) playfield[row, col].Type = rook; if (col == 1 || col == 6) playfield[row, col].Type = knight; if (col == 2 || col == 5) playfield[row, col].Type = bishop; if (col == 3) playfield[row, col].Type = queen; if (col == 4) playfield[row, col].Type = king; } if (row == 1 || row == 6) playfield[row, col].Type = pawn; //set piece color if (row <= 1) playfield[row, col].Colour = black; if (row >= 6) playfield[row, col].Colour = white; if (row <= 1 || row >= 6) playfield[row, col].Exists = true; } for (int col = 0; col < 2; col++) { whiteTaken[row, col] = new Piece(); blackTaken[row, col] = new Piece(); } } }
void rookMoveHighlight(Piece.Colour colour, int row, int col, List<int[]> moveable, Piece[,] board) { bool canContinue = true; int i = 1; //check down while (canContinue) { addMoveable(row, col, i, 0, moveable, board); if (!uf.IsInBounds(row + i) || (uf.IsInBounds(row + i) && board[row + i, col].Exists)) canContinue = false; i++; } //check up i = 1; canContinue = true; while (canContinue) { addMoveable(row, col, -i, 0, moveable, board); if (!uf.IsInBounds(row - i) || (uf.IsInBounds(row - i) && board[row - i, col].Exists)) canContinue = false; i++; } //check right i = 1; canContinue = true; while (canContinue) { addMoveable(row, col, 0, i, moveable, board); if (!uf.IsInBounds(col + i) || (uf.IsInBounds(col + i) && board[row, col + i].Exists)) canContinue = false; i++; } //check left i = 1; canContinue = true; while (canContinue) { addMoveable(row, col, 0, -i, moveable, board); if (!uf.IsInBounds(col - i) || (uf.IsInBounds(col - i) && board[row, col - i].Exists)) canContinue = false; i++; } }
void bishopMoveHighlight(string colour, int row, int col, List<int[]> moveable, Piece[,] board) { int i = 1; bool canContinue = true; //check down right while (canContinue) { addMoveable(row, col, i, i, moveable, board); if (!uf.IsInBounds(row + i, col + i) || (uf.IsInBounds(row + i, col + i) && board[row + i, col + i].Exists)) canContinue = false; i++; } //check up right i = 1; canContinue = true; while (canContinue) { addMoveable(row, col, -i, i, moveable, board); if (!uf.IsInBounds(row - i, col + i) || (uf.IsInBounds(row - i, col + i) && board[row - i, col + i].Exists)) canContinue = false; i++; } //check up left i = 1; canContinue = true; while (canContinue) { addMoveable(row, col, -i, -i, moveable, board); if (!uf.IsInBounds(row - i, col - i) || (uf.IsInBounds(row - i, col - i) && board[row - i, col - i].Exists)) canContinue = false; i++; } //check down left i = 1; canContinue = true; while (canContinue) { addMoveable(row, col, i, -i, moveable, board); if (!uf.IsInBounds(row + i, col - i) || (uf.IsInBounds(row + i, col - i) && board[row + i, col - i].Exists)) canContinue = false; i++; } }