public void attemptsToMove(MouseState click, ref ChessBoard chess) // move logic for each player { if (selectionTile == null) { return; } King checkedBlackKing = (King)chess.Pieces[20]; King checkedWhiteKing = (King)chess.Pieces[21]; if (click.LeftButton == ButtonState.Pressed) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (chess.Tiles[i, j].getBorder().Contains(new Point(click.X, click.Y)) && selectionTile.PieceInside != null) { if (WhitePlayerTurn && selectionTile.PieceInside.IsWhite) { if (selectionTile.PieceInside.move(ref selectionTile, ref chess.Tiles[i, j], chess)) { //winning condition chess.resetAttackedTiles(); chess.promotePawn(ChessGame.Content); for (int k = 0; k < 32; k++) { if (chess.Pieces[k] != null) { chess.Pieces[k].attackTile(ref chess); } } checkedBlackKing.clearKing(); if (checkedBlackKing.checkPath(ref chess)) { chess.resetAttackedTiles(); for (int k = 0; k < 32; k++) { if (chess.Pieces[k] != null) { if ((chess.Pieces[k] is Pawn && !chess.Pieces[k].IsWhite) || k == 20) { continue; } chess.Pieces[k].attackTile(ref chess); } } } checkedBlackKing.checkmate(ChessGame.player1, ChessGame.player2, ref chess); WhitePlayerTurn = !WhitePlayerTurn; return; } } else if (!(WhitePlayerTurn) && !(selectionTile.PieceInside.IsWhite)) { if (selectionTile.PieceInside.move(ref selectionTile, ref chess.Tiles[i, j], chess)) { chess.resetAttackedTiles(); chess.promotePawn(ChessGame.Content); for (int k = 0; k < 32; k++) { if (chess.Pieces[k] != null) { chess.Pieces[k].attackTile(ref chess); } } checkedWhiteKing.clearKing(); if (checkedWhiteKing.checkPath(ref chess)) { chess.resetAttackedTiles(); for (int k = 0; k < 32; k++) { if (chess.Pieces[k] != null) { if ((chess.Pieces[k] is Pawn && chess.Pieces[k].IsWhite) || k == 21) { continue; } chess.Pieces[k].attackTile(ref chess); } } } checkedWhiteKing.checkmate(ChessGame.player1, ChessGame.player2, ref chess); WhitePlayerTurn = !WhitePlayerTurn; return; } } } } } } }