// make move public void makeMove(Move Move) { board[Move.getNewX(), Move.getNewY()] = board[Move.getPrevX(), Move.getPrevY()]; board[Move.getPrevX(), Move.getPrevY()] = null; if (Move.getIsBeating()) { if (board[Move.getBeatingX(), Move.getBeatingY()].isFirstPlayer()) { --firstPawns; } else if (!board[Move.getBeatingX(), Move.getBeatingY()].isFirstPlayer()) { --secondPawns; } board[Move.getBeatingX(), Move.getBeatingY()] = null; if (Move.getNextBeating() != null) { makeMove(Move.getNextBeating()); } else { grandForKing(Move.getNewX(), Move.getNewY()); } } else { grandForKing(Move.getNewX(), Move.getNewY()); } }
//deep copy public Move(Move move) { this.prevX = move.getPrevX(); this.prevY = move.getPrevY(); this.newX = move.getNewX(); this.newY = move.getNewY(); this.beatenX = move.getBeatingX(); this.beatenY = move.getBeatingY(); this.isBeating = move.getIsBeating(); this.prevBeating = move.getPrevBeating(); this.nextBeating = move.getNextBeating(); }
private void playerControl(int x, int y) { int[,] b = board.checkPawns(); if (b[x, y] == 1 || b[x, y] == 3 || b[x, y] == 2 || b[x, y] == 4) { pawnX = x; pawnY = y; pawnChosen = true; for (int xx = 0; xx < 8; xx++) { for (int yy = 0; yy < 8; yy++) { if (fields[xx, yy] != null) { fields[xx, yy].Image = unsigned.Image; } } } fields[x, y].Image = signed.Image; foreach (Move move in playerMovements) { if (move.getPrevX() == x && move.getPrevY() == y) { fields[move.getNewX(), move.getNewY()].Image = signed.Image; } } foreach (Move move in playerBeatings) { if (move.getPrevX() == x && move.getPrevY() == y) { fields[move.getNewX(), move.getNewY()].Image = signed.Image; } } } else if (pawnChosen) { moveX = x; moveY = y; foreach (Move move in playerMovements) { if (move.getPrevX() == pawnX && move.getPrevY() == pawnY && move.getNewX() == moveX && move.getNewY() == moveY && playerBeatings.Count() == 0) { moveDone = true; pawnChosen = false; board.makeMove(move); for (int xx = 0; xx < 8; xx++) { for (int yy = 0; yy < 8; yy++) { if (fields[xx, yy] != null) { fields[xx, yy].Image = unsigned.Image; } } } } } foreach (Move move in playerBeatings) { if (move.getPrevX() == pawnX && move.getPrevY() == pawnY && move.getNewX() == moveX && move.getNewY() == moveY && !moveDone) { moveDone = true; pawnChosen = false; board.makeMove(move); for (int xx = 0; xx < 8; xx++) { for (int yy = 0; yy < 8; yy++) { if (fields[xx, yy] != null) { fields[xx, yy].Image = unsigned.Image; } } } } } } label4.Text = "Player pawn: x= " + pawnX + ", y= " + pawnY + ", move: x= " + moveX + ", y= " + moveY; }