private void ChangeLeft(int x, int y) { int i = x - 1; int j = y; while (i >= 1) { Square sq = gameBoard.squares[i, j]; if (sq.isOccupied() && Math.Abs(sq.getX() - x) == 1) { if (sq.getPiece().getColor() == currPlayer.getPlayerColor()) { break; } else { i--; } continue; } else { if (sq.isOccupied() && sq.getPiece().getColor() == currPlayer.getPlayerColor()) { changeBetween(i, j, x, y); break; } else { i--; } continue; } } }
private void ChangeUpRight(int x, int y) { int i = x + 1; int j = y - 1; while (j >= 1 && i <= 7) { Square sq = gameBoard.squares[i, j]; if (sq.isOccupied() && Math.Abs(sq.getY() - y) == 1 && Math.Abs(sq.getX() - x) == 1) { if (sq.getPiece().getColor() == currPlayer.getPlayerColor()) { break; } else { i++; } j--; continue; } else { if (sq.isOccupied() && sq.getPiece().getColor() == currPlayer.getPlayerColor()) { changeBetween(i, j, x, y); break; } else { i++; } j--; continue; } } }
private void ChangeDown(int x, int y) { int i = x; int j = y + 1; while (j <= 7) { Square sq = gameBoard.squares[i, j]; if (sq.isOccupied() && Math.Abs(sq.getY() - y) == 1) { if (sq.getPiece().getColor() == currPlayer.getPlayerColor()) { break; } else { j++; } continue; } else { if (sq.isOccupied() && sq.getPiece().getColor() == currPlayer.getPlayerColor()) { changeBetween(i, j, x, y); break; } else { j++; } continue; } } }
private void checkUpLeft(Square currentSquare, Player cPlayer) { int i = currentSquare.getX(); int j = currentSquare.getY(); while (i >= 2 && j >= 2) { Square sq = squares[i - 1, j - 1]; if (currentSquare.getY() - sq.getY() >= 2 && currentSquare.getX() - sq.getX() >= 2 && sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor()) { if (LRDiagonalCheck(sq, currentSquare)) { Moves.Add(new Move(cPlayer, currentSquare)); } break; } else if (currentSquare.getY() - sq.getY() <= 1 && currentSquare.getX() - sq.getX() <= 1 && sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor()) { break; } i -= 1; j -= 1; } }
private void checkDownRight(Square currentSquare, Player cPlayer) { int i = currentSquare.getX(); int j = currentSquare.getY(); while (j <= 7 && i <= 7) { Square sq = squares[i + 1, j + 1]; if (sq.getY() - currentSquare.getY() >= 2 && sq.getX() - currentSquare.getX() >= 2 && sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor()) { if (LRDiagonalCheck(currentSquare, sq)) { Moves.Add(new Move(cPlayer, currentSquare)); } break; } else if (currentSquare.getY() - sq.getY() <= 1 && currentSquare.getX() - sq.getX() <= 1 && sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor()) { break; } i += 1; j += 1; } }
private void checkLeft(Square currentSquare, Player cPlayer) { int i = currentSquare.getX(); int j = currentSquare.getY(); while (i >= 2) { //Console.WriteLine(i + " " + j); Square sq = squares[i - 1, j]; if (currentSquare.getX() - sq.getX() >= 2 && sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor()) { //Console.WriteLine("Same square found " + sq.getX() + " " + sq.getY()); if (checkHorizontalBetween(sq, currentSquare)) { Moves.Add(new Move(cPlayer, currentSquare)); } break; } else if (currentSquare.getX() - sq.getX() <= 1 && sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor()) { break; } i -= 1; } }
private void checkDown(Square currentSquare, Player cPlayer) { int i = currentSquare.getX(); int j = currentSquare.getY(); while (j <= 7) { //Console.WriteLine(i + " " + j); Square sq = squares[i, j + 1]; if (sq.getY() - currentSquare.getY() >= 2 && sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor()) { //Console.WriteLine("Same square found " + sq.getX() + " " + sq.getY()); Console.WriteLine("About to Check between " + currentSquare.getY() + " " + sq.getY()); if (CheckVerticalBetween(currentSquare, sq)) { Moves.Add(new Move(cPlayer, currentSquare)); } break; } else if (currentSquare.getY() - sq.getY() <= 1 && sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor()) { break; } j += 1; } }
private bool RLDiagonalCheck(Square s1, Square s2) { bool addition = false; int i = s1.getX(); int j = s1.getY(); if (s1.getX() - s2.getX() == 2 && s2.getY() - s1.getY() == 2) { if (squares[i - 1, j + 1].isOccupied() && s1.isOccupied() && squares[i - 1, j + 1].getPiece().getColor() != s1.getPiece().getColor()) { addition = true; } } else { Square required = squares[i - 1, j + 1]; while (i > s2.getX() && j < s2.getY()) { if (squares[i, j].isOccupied() && required.isOccupied() && squares[i, j].getPiece().getColor() == required.getPiece().getColor()) { addition = true; } else { addition = false; } i -= 1; j += 1; } } return(addition); }
public bool IsValid() { if (movingSquare.isOccupied()) { return(false); } return(true); }
private bool checkHorizontalBetween(Square s1, Square s2) { //Console.WriteLine("From " + s1.getX() + " To " + s2.getX()); bool addition = false; int j = s1.getY(); if (s2.getX() - s1.getX() == 2) { //Console.WriteLine("Checking " + (s1.getX() + 1) + " " + j); //Console.WriteLine(s1.getPiece().getColor().ToString()); if (squares[s1.getX() + 1, j].isOccupied() && s1.isOccupied() && squares[s1.getX() + 1, j].getPiece().getColor() != s1.getPiece().getColor()) { //Console.WriteLine("Square Found"); addition = true; } } else { Square required = squares[s1.getX() + 1, j]; Console.WriteLine("Checking from " + (s1.getX() + 1) + " to " + (s2.getX() - 1)); for (int i = s1.getX() + 1; i < s2.getX(); i++) { if (squares[i, j].isOccupied() && required.isOccupied() && squares[i, j].getPiece().getColor() == required.getPiece().getColor()) { //Console.WriteLine("Same squares are " + i + " " + (i + 1)); addition = true; } else { addition = false; } } /* if (addition) * Console.WriteLine("From " + (s1.getX()+1) + " to " + (s2.getX()-1) + " Are the Same");*/ } return(addition); }