private int eval(CheckersBoard board) { int colorKing; int colorForce = 0; int enemyForce = 0; int piece; if (color == CheckersBoard.WHITE) { colorKing = CheckersBoard.WHITE_KING; } else { colorKing = CheckersBoard.BLACK_KING; } try { for (int i = 0; i < 32; i++) { piece = board.getCell(i); if (piece != CheckersBoard.EMPTY) { if (piece == color || piece == colorKing) { colorForce += calculateValue(piece, i); } else { enemyForce += calculateValue(piece, i); } } } } catch { } return(colorForce - enemyForce); }
public void panel_Paint(object sender, PaintEventArgs e) { g = e.Graphics; Size d = (sender as Panel).Size; int pos, x, y; Brush cellColor; Brush brushBlack = new SolidBrush(Color.Black); Brush brushWhite = new SolidBrush(Color.White); Brush brushLightGreen = new SolidBrush(Color.LightGreen); Brush brushBurlyWood = new SolidBrush(Color.BurlyWood); Brush brushChocolate = new SolidBrush(Color.Chocolate); Brush brushDarkOliveGreen = new SolidBrush(Color.DarkOliveGreen); // Поле for (y = 0; y < 8; y++) { for (x = 0; x < 8; x++) { if ((x + y) % 2 != 0) { pos = y * 4 + (x + ((y % 2 == 0) ? 0 : 1)) / 2; if (board.selected.has(pos)) { cellColor = brushLightGreen; // Если фишка выбрана клетка зелёного цвета } else { cellColor = brushBlack; } } else { cellColor = brushWhite; } g.FillRectangle(cellColor, x * 50, y * 50, 50 - 1, 50 - 1); } } // Фишки byte cell; for (int i = 0; i < 32; i++) { try { cell = board.getCell(i); if (cell != CheckersBoard.EMPTY) { y = i / 4; x = (i % 4) * 2 + (y % 2 == 0 ? 1 : 0); if (cell == CheckersBoard.BLACK || cell == CheckersBoard.BLACK_KING) { g.FillEllipse(brushBurlyWood, CHIP_SIZE + x * 50, CHIP_SIZE + y * 50, 50 - 1 - 2 * CHIP_SIZE, 50 - 1 - 2 * CHIP_SIZE); } else { g.FillEllipse(brushChocolate, CHIP_SIZE + x * 50, CHIP_SIZE + y * 50, 50 - 1 - 2 * CHIP_SIZE, 50 - 1 - 2 * CHIP_SIZE); } if (cell == CheckersBoard.WHITE_KING) { g.DrawEllipse(new Pen(brushDarkOliveGreen), KING_SIZE + x * 50, KING_SIZE + y * 50, 50 - KING_SIZE, 50 - KING_SIZE); } else if (cell == CheckersBoard.BLACK_KING) { g.DrawEllipse(new Pen(brushDarkOliveGreen), KING_SIZE + x * 50, KING_SIZE + y * 50, 50 - KING_SIZE, 50 - KING_SIZE); } } } catch { } } }