public override List <dStruct> getPossibleMoves(figure[,] _board, ChessModel _game) { List <dStruct> possibleMoves = new List <dStruct>(); for (int i = 0; i <= Rook.stepsForCheck.Length - 1; i++) { int ix = this.x + Rook.stepsForCheck[i].dx; int iy = this.y + Rook.stepsForCheck[i].dy; while (ix <= 7 && iy <= 7 && ix >= 0 && iy >= 0) { if (_board[iy, ix] == null) { possibleMoves.Add(new dStruct(ix, iy)); } else { if (_board[iy, ix].getColor() != this.getColor()) { possibleMoves.Add(new dStruct(ix, iy)); } break; } ix += Rook.stepsForCheck[i].dx; iy += Rook.stepsForCheck[i].dy; } } return(possibleMoves); }
public ChessUI(NetworkStream stream, figureColor color) { InitializeComponent(); this.stream = stream; this.color = color; btn_light.BackColor = color == figureColor.White ? Color.Green : Color.Red; generateButtonArray(color); setFiguresOnStart(); pawnTransform = new Image[, ] { { null, imageList1.Images[4], imageList1.Images[5], imageList1.Images[0], null, imageList1.Images[2] }, { null, imageList1.Images[10], imageList1.Images[11], imageList1.Images[6], null, imageList1.Images[8] } }; game = new ChessModel(color); if (color == figureColor.White) { Text = "Chess - Host"; InfoLabel.Text = "You are the first"; } else { Text = "Chess - Client"; InfoLabel.Text = "Your opponent is the first"; } WaitForResponse(); }
public override List <dStruct> getPossibleMoves(figure[,] _board, ChessModel _game) { List <dStruct> possibleMoves = getPossibleMovesFire(_board); possibleMoves.AddRange(getPossibleMovesNotFire(_board)); return(possibleMoves); }
public ChessUI(NetworkStream stream, String color) { InitializeComponent(); GenerateButtonArray(); this.stream = stream; this.game = new ChessModel(color); listBox1.SelectionMode = SelectionMode.None; if (color == "Black") { this.Text = "Chess - Host"; this.listBox1.Items.Add("Your opponent goes first"); //rows this.label3.Text = "7"; this.label2.Text = "6"; this.label4.Text = "5"; this.label5.Text = "4"; this.label8.Text = "3"; this.label9.Text = "2"; this.label6.Text = "1"; this.label7.Text = "0"; //columns this.label1.Text = "7"; this.label10.Text = "6"; this.label12.Text = "5"; this.label11.Text = "4"; this.label16.Text = "3"; this.label15.Text = "2"; this.label14.Text = "1"; this.label13.Text = "0"; } else { this.Text = "Chess - Client"; this.listBox1.Items.Add("It's your turn first"); //rows this.label3.Text = "0"; this.label2.Text = "1"; this.label4.Text = "2"; this.label5.Text = "3"; this.label8.Text = "4"; this.label9.Text = "5"; this.label6.Text = "6"; this.label7.Text = "7"; //columns this.label1.Text = "0"; this.label10.Text = "1"; this.label12.Text = "2"; this.label11.Text = "3"; this.label16.Text = "4"; this.label15.Text = "5"; this.label14.Text = "6"; this.label13.Text = "7"; } UpdateBoard(); if (!game.IsTurn()) { WaitForResponse(); } }
private void btn_newGame_Click(object sender, EventArgs e) { game = new ChessModel(color); setFiguresOnStart(); WriteMessage(new byte[] { (byte)signalType.newGame }); ((Button)sender).Enabled = false; btn_light.BackColor = Color.Green; }
public override List <dStruct> getPossibleMoves(figure[,] _board, ChessModel _game) { List <dStruct> possibleMoves = new List <dStruct>(); int ix; int iy; for (int i = 0; i <= Knight.stepsForCheck.Length - 1; i++) { ix = this.x + Knight.stepsForCheck[i].dx; iy = this.y + Knight.stepsForCheck[i].dy; if ((ix <= 7 && iy <= 7 && ix >= 0 && iy >= 0) && (_board[iy, ix] == null || (_board[iy, ix].getColor() != this.getColor()))) { possibleMoves.Add(new dStruct(ix, iy)); } } return(possibleMoves); }
public override List <dStruct> getPossibleMoves(figure[,] _board, ChessModel _game) { List <dStruct> possibleMoves = new List <dStruct>(); int ix; int iy; for (int i = 0; i <= King.stepsForCheck.Length - 1; i++) { ix = this.x + King.stepsForCheck[i].dx; iy = this.y + King.stepsForCheck[i].dy; if ((ix <= 7 && iy <= 7 && ix >= 0 && iy >= 0) && (_board[iy, ix] == null || (_board[iy, ix].getColor() != this.getColor()))) { possibleMoves.Add(new dStruct(ix, iy)); } } ///длинная рокиррвка для белых if (!isMoved && _board[0, 0] != null && !_board[0, 0].isMoved && _board[0, 1] == null && _board[0, 2] == null && _board[0, 3] == null && !_game.isChecked() && _game.isValidMove_Ch(x, y, 3, 0) && _game.isValidMove_Ch(x, y, 2, 0) && getColor() == figureColor.White) { possibleMoves.Add(new dStruct(2, 0)); } //короткая для белых if (!isMoved && _board[0, 7] != null && !_board[0, 7].isMoved && _board[0, 5] == null && _board[0, 6] == null && !_game.isChecked() && _game.isValidMove_Ch(x, y, 6, 0) && _game.isValidMove_Ch(x, y, 5, 0) && getColor() == figureColor.White) { possibleMoves.Add(new dStruct(6, 0)); } //длинная для черных if (!isMoved && _board[7, 0] != null && !_board[7, 0].isMoved && _board[7, 1] == null && _board[7, 2] == null && _board[7, 3] == null && !_game.isChecked() && _game.isValidMove_Ch(x, y, 3, 7) && _game.isValidMove_Ch(x, y, 2, 7) && getColor() == figureColor.Black) { possibleMoves.Add(new dStruct(2, 7)); } //короткая для черных if (!isMoved && _board[7, 7] != null && !_board[7, 7].isMoved && _board[7, 5] == null && _board[7, 6] == null && !_game.isChecked() && _game.isValidMove_Ch(x, y, 6, 7) && _game.isValidMove_Ch(x, y, 5, 7) && getColor() == figureColor.Black) { possibleMoves.Add(new dStruct(6, 7)); } return(possibleMoves); }
public ChessUI(NetworkStream stream, String color) { InitializeComponent(); GenerateButtonArray(); this.stream = stream; this.game = new ChessModel(color); if (color == "Black") { this.Text = "Chess - Host"; this.InfoLabel.Text = "Your opponent goes first"; } else { this.Text = "Chess - Client"; this.InfoLabel.Text = "It's your turn first"; } UpdateBoard(); if (!game.IsTurn()) { WaitForResponse(); } }
public abstract List <dStruct> getPossibleMoves(figure[,] _board, ChessModel _game);
private async void WaitForResponse() { try { while (true) { if (stream.CanRead) { string move; byte[] bytes = new byte[256]; await stream.ReadAsync(bytes, 0, bytes.Length); if (bytes[0] == (byte)signalType.disconnect) { InfoLabel.Text = "Disconnected"; game.isGameOver = true; break; } else { switch (bytes[0]) { case (byte)signalType.ordinaryMove: case (byte)signalType.castlingNearWhite: case (byte)signalType.castlingFarWhite: case (byte)signalType.castlingNearBlack: case (byte)signalType.castlingFarBlack: //обработка пришедшего хода move = game.board[bytes[2], bytes[1]].getColor().ToString() + ' ' + game.board[bytes[2], bytes[1]].getName().ToString() + " (" + chars[bytes[1]] + (bytes[2] + 1).ToString() + ")->(" + chars[bytes[3]] + (bytes[4] + 1).ToString() + ')'; lastMove.Text = move; UpdateBoard(bytes); game.makeMove(bytes); game.changeTurn(); btn_light.BackColor = Color.Green; if (!game.isMovesExist() && !game.isChecked()) { lblLoseWin.Text = "Pat"; WriteMessage(new byte[] { (byte)signalType.pat }); if (color == figureColor.White) { btn_newGame.Enabled = true; } } else if (game.isChecked() && !game.isMovesExist()) { lblLoseWin.Text = "Mat. You lose"; WriteMessage(new byte[] { (byte)signalType.mat }); if (color == figureColor.White) { btn_newGame.Enabled = true; } } else if (game.isChecked() && game.isMovesExist()) { lblLoseWin.Text = "Checked"; } else { lblLoseWin.Text = ""; } break; case (byte)signalType.pawnTransfom: move = game.board[bytes[2], bytes[1]].getColor().ToString() + ' ' + game.board[bytes[2], bytes[1]].getName().ToString() + " (" + chars[bytes[1]] + (bytes[2] + 1).ToString() + ")->(" + chars[bytes[3]] + (bytes[4] + 1).ToString() + ')'; lastMove.Text = move; UpdateBoardPawnTransfom(new byte[] { bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6] }); game.makePawnTransformMove(new byte[] { bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6] }); game.changeTurn(); btn_light.BackColor = Color.Green; if (!game.isMovesExist() && !game.isChecked()) { lblLoseWin.Text = "Pat"; WriteMessage(new byte[] { (byte)signalType.pat }); if (color == figureColor.White) { btn_newGame.Enabled = true; } } else if (game.isChecked() && !game.isMovesExist()) { lblLoseWin.Text = "Mat. You lose"; WriteMessage(new byte[] { (byte)signalType.mat }); if (color == figureColor.White) { btn_newGame.Enabled = true; } } else if (game.isChecked() && game.isMovesExist()) { lblLoseWin.Text = "Checked"; } else { lblLoseWin.Text = ""; } break; case (byte)signalType.mat: if (color == figureColor.White) { btn_newGame.Enabled = true; } lblLoseWin.Text = "Mat.You win"; break; case (byte)signalType.pat: if (color == figureColor.White) { btn_newGame.Enabled = true; } lblLoseWin.Text = "Pat"; break; case (byte)signalType.newGame: btn_light.BackColor = Color.Red; game = new ChessModel(color); setFiguresOnStart(); break; } /* else * /* */ } } } } catch (ObjectDisposedException err) { InfoLabel.Text = "Opponent disconnected. You won!"; } finally { if (stream != null) { stream.Close(); } } }