public Step(Step s) { FromX = s.FromX; FromY = s.FromY; ToX = s.ToX; ToY = s.ToY; }
private void AIStep(object p) { var timer = new Stopwatch(); timer.Start(); _ai.Count = 0; var state = _game.calcState(); if (state == State.Draw) { MessageBox.Show("Пат"); return; } if (state == State.Checkmate) { MessageBox.Show("Компьютерный игрок проиграл"); return; } var s = _ai.SelectMove((Player)p, 4, _mainBoard); _game.doMove(s); AddStepForHistory(s); _lastStep = s; ThreadEnd(); timer.Stop(); if (labelTime.InvokeRequired) labelTime.BeginInvoke(new Action<string>(x => labelTime.Text = x), timer.ElapsedMilliseconds.ToString()+ " Просмотренно узлов: " + _ai.Count.ToString()); else labelTime.Text = timer.ElapsedMilliseconds.ToString(); }
public static void PrecalcStep() { for (var j = 0; j < 64; j++) { var f = new StepFromPosition(4); var x = j >> 3; var y = j & 7; for (var i = 0; i < 4; i++) { var nx = x + _dx[i]; var ny = y + _dy[i]; Ray last = null; if (nx >= 0 && nx < 8 && ny >= 0 && ny < 8) { var s = new Step(x, y, nx, ny); var r = new Ray(s); f.Rays[i] = r; last = r; f.Attack.Add((nx << 3) + ny, i); } nx += _dx[i]; ny += _dy[i]; while (nx >= 0 && nx < 8 && ny >= 0 && ny < 8) { var s = new Step(x, y, nx, ny); f.Attack.Add((nx << 3) + ny, i); var n = new Ray(s); last.NextRay = n; last = n; nx += _dx[i]; ny += _dy[i]; } } pSteps[j] = f; } }
public StepsNode(Step s, StepsNode next = null, StepsNode special = null) { _step = s; nextNode = next; nextSpecialNode = special; }
//делает ход и заносит в стек информацию //о том, что необходимо для его отмены static void DoMove(Step step, Board board) { board.Move(step); }
public void doMove(Step s) { _board.Move(s); Player = getEnemy(Player); }
public Ray(Step s, Ray next = null) { step = s; NextRay = next; }
private void Form1_Load(object sender, EventArgs e) { comboBox1.SelectedIndex = comboBox2.SelectedIndex = 0; Functions.Precalc(); _tWhite = TypeOfGamer.Human; _tBlack = TypeOfGamer.Human; _curPlayer = Player.White; _game = new Game(_mainBoard); _ai = new AI(); _lastStep = null; pictureBox1.Invalidate(); }
private void AddStepForHistory(Step s) { if (listView1.InvokeRequired) listView1.BeginInvoke(new Action<string>(str => listView1.Items.Add(str)), s.ToString()); else listView1.Items.Add(s.ToString()); }
private void PrintBoard(Control panel, PaintEventArgs e) { //создаем буффер и контекст для него //определяем контекст BufferedGraphicsContext context = BufferedGraphicsManager.Current; //определяем размер контекста context.MaximumBuffer = new Size(panel.Width + 1, panel.Height + 1); var rec = new Rectangle(0, 0, panel.Width, panel.Height); //на основе контекста создаем буфер BufferedGraphics buffer = context.Allocate(e.Graphics, rec); //отрисовка чего то там Brush brushWhite = new SolidBrush(Color.White); Brush brushBlack = new SolidBrush(Color.Black); var whiteP = new Pen(Color.White); for (var i = 0; i < 8; i++) { for (var j = 0; j < 8; j++) { if ((j + i) % 2 == 1) { buffer.Graphics.FillRectangle(brushBlack, 70 * i, 70 * j, 70, 70); } else { buffer.Graphics.FillRectangle(brushWhite, 70 * i, 70 * j, 70,70); } buffer.Graphics.DrawRectangle(whiteP, 70 * i, 70 * j, 70, 70); } } if (_lastStep != null) { Brush c = new SolidBrush(Color.Yellow); buffer.Graphics.FillRectangle(c, 70 * _lastStep.FromY, 70 * (7 - _lastStep.FromX), 70, 70); buffer.Graphics.DrawRectangle(whiteP, 70 * _lastStep.FromY, 70 * (7 - _lastStep.FromX), 70, 70); buffer.Graphics.FillRectangle(c, 70 * _lastStep.ToY, 70 * (7 - _lastStep.ToX), 70, 70); buffer.Graphics.DrawRectangle(whiteP, 70 * _lastStep.ToY, 70 * (7 - _lastStep.ToX), 70, 70); _lastStep = null; } if (_isSelectFigure) { Brush green = new SolidBrush(Color.GreenYellow); buffer.Graphics.FillRectangle(green, 70 * sy, 70 * (7 - sx), 70, 70); buffer.Graphics.DrawRectangle(whiteP,70 * sy, 70 * (7 - sx), 70, 70); var steps = _mainBoard[(sx << 3) + sy].GetRightMove(); var allSteps = _game.getAllLegalMoves(_curPlayer); var rSteps = steps.Where(x => { var s = allSteps.FirstOrDefault(y => x.FromX == y.FromX && x.FromY == y.FromY && x.ToX == y.ToX && x.ToY == y.ToY); return s != null; } ); Brush blue = new SolidBrush(Color.BlueViolet); Brush red = new SolidBrush(Color.Red); foreach (var x in rSteps) { buffer.Graphics.FillRectangle(_mainBoard[(x.ToX << 3) + x.ToY] == null ? blue : red, x.ToY*70, (7 - x.ToX)*70, 70, 70); buffer.Graphics.DrawRectangle(whiteP, x.ToY * 70, (7 - x.ToX) * 70, 70, 70); } } for (var i = 0; i < 8; i++) { for (var j = 0; j < 8; j++) { if (_mainBoard[(i << 3) + j] != null) { var path = "Picture/" + _mainBoard[(i << 3) + j].PictureName() + ".png"; var img = Image.FromFile(path); buffer.Graphics.DrawImage(img, 70 * j, 70 * (7-i)); } } } //закончили отрисовку //Выводим буффер на экран buffer.Render(e.Graphics); //и очищаем память buffer.Dispose(); }
private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { if (_isBlock) return; var nsy = e.X / 70; var nsx = 7 - (e.Y / 70); if (_isSelectFigure) { if (nsx == sx && nsy == sy) { _isSelectFigure = false; pictureBox1.Invalidate(); } else { try { var s = new Step(sx, sy, nsx, nsy); _game.doMove(s); AddStepForHistory(s); _curPlayer = _game.Player; } catch (ErrorStepExveption ex) { MessageBox.Show("Недопустимый ход!"); } _isSelectFigure = false; pictureBox1.Invalidate(); } } else { sx = nsx; sy = nsy; if (_mainBoard[(sx << 3) + sy] == null || _mainBoard[(sx << 3) + sy].Player != _curPlayer) return; _isSelectFigure = true; pictureBox1.Invalidate(); } }