public OthelloGame(IBoardWriter board) { m_board = board; m_playerBlack = new Player() { Type = PlayerType.Player, Color = FieldValue.Black }; m_playerWhite = new Player() { Type = PlayerType.Player, Color = FieldValue.White }; ActivePlayer = m_playerBlack; }
public override int Evaluate(Panel[,] board, Player p,int tileCount) { List<Panel> white_panels = new List<Panel>(); List<Panel> black_panels = new List<Panel>(); for (int i = 0; i < tileCount; i++) for (int j = 0; j < tileCount; j++) { if (board[i, j].Tag.ToString() == "W") white_panels.Add(board[i, j]); else if (board[i, j].Tag.ToString() == "B") black_panels.Add(board[i, j]); } switch (p.Color) { case "W": return white_panels.Capacity - black_panels.Capacity; case "B": return black_panels.Capacity - white_panels.Capacity; } return 0; }
public override int Evaluate(Panel[,] board, Player p,int tileCount) { return 0; }
public virtual int Evaluate(Panel[,] board, Player p,int tileCount) { return 0; }
public void Restart() { ActivePlayer = m_playerBlack; m_board.ClearBoard(); m_board.SetStartValues(); }
private void ToggleActivePlayer() { ActivePlayer = ActivePlayer == m_playerBlack ? m_playerWhite : m_playerBlack; }
public Game(Game_Panel gamePanel, int boardSize, string FuncW, string FuncB, bool test_mode) { WhiteSemaphore = new Semaphore(0, 1); BlackSemaphore = new Semaphore(1, 1); whitePlayer = new Player(FuncW, "W",boardSize); blackPlayer = new Player(FuncB, "B",boardSize); whitePlayer.setOpponent(blackPlayer); blackPlayer.setOpponent(whitePlayer); this.gamePanel = gamePanel; this.boardSize = boardSize; this.test_mode = test_mode; ///z zasad gry: Czarny zawsze zaczyna gre! turn = Turn.B; int squareSize = boardSize / 3; tileSize = (gamePanel.gameBoard.Width) / boardSize; int gridSize = boardSize; int half = gridSize / 2; // inicjalizacja planszy Tiles = new Panel[gridSize, gridSize]; for (var n = 0; n < gridSize; n++) { for (var m = 0; m < gridSize; m++) { var newPanel = new Panel { Size = new Size(tileSize, tileSize), Location = new Point(tileSize * n, tileSize * m) }; Tiles[n, m] = newPanel; // color the backgrounds if (n % 2 == 0) { newPanel.BackgroundImage = (System.Drawing.Image)(Image.FromFile("GreenField.png")); newPanel.Tag = "G"; } else { newPanel.BackgroundImage = (System.Drawing.Image)(Image.FromFile("GreenField.png")); newPanel.Tag = "G"; } newPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; if ((n < squareSize && m < squareSize) || (n >= 2 * squareSize && m >= 2 * squareSize) || (n < squareSize && m >= 2 * squareSize) || (m < squareSize && n >= 2 * squareSize)) { newPanel.BackgroundImage = (System.Drawing.Image)(Image.FromFile("EmptyField.png")); newPanel.Tag = "E"; } gamePanel.gameBoard.Controls.Add(newPanel); } } ///ustawienie 4 pionkow na srodku planszy Panel p = Tiles[half, half]; p.BackgroundImage = (System.Drawing.Image)(Image.FromFile("WField.png")); p.Tag = "W"; p = Tiles[half - 1, half - 1]; whitePlayer.Points++; p.BackgroundImage = (System.Drawing.Image)(Image.FromFile("WField.png")); p.Tag = "W"; whitePlayer.Points++; p = Tiles[half, half - 1]; p.BackgroundImage = (System.Drawing.Image)(Image.FromFile("BlackField.png")); p.Tag = "B"; blackPlayer.Points++; p = Tiles[half - 1, half]; p.BackgroundImage = (System.Drawing.Image)(Image.FromFile("BlackField.png")); p.Tag = "B"; blackPlayer.Points++; //TEST MODE - testowanie interakcji GUI z logiką gry (naprzemienne klikanie myszką pol) if (test_mode) { for (var n = 0; n < gridSize; n++) { for (var m = 0; m < gridSize; m++) { if (Tiles[n, m].Tag.ToString() == "G") { this.Tiles[n, m].Click += new System.EventHandler(this.Tile_Click); this.Tiles[n, m].MouseEnter += new System.EventHandler(this.Tile_Enter); this.Tiles[n, m].MouseLeave += new System.EventHandler(this.Tile_Leave); } } } } //w przeciwnym przypadku naprzemienne uruchamianie graczy else { searcher = new Searcher(tileSize, boardSize); Start(); } }
/// <summary> /// odwroc kolor pionka zgodnie z obecnym ruchem (czy bialy czy czarny) /// </summary> /// <param name="p"></param> /// <param name="tag"></param> /// <param name="opposite_tag"></param> /// <param name="secondPlayer"></param> /// <param name="currentPlayer"></param> /// <param name="file"></param> private void Reverse(Panel p, string tag, string opposite_tag, Player secondPlayer, Player currentPlayer, string file) { if (p.Tag.ToString() == opposite_tag) { secondPlayer.Points--; p.Tag = tag; p.BackgroundImage = (System.Drawing.Image)(Image.FromFile(file)); p.Click += null; p.MouseEnter += null; p.MouseLeave += null; currentPlayer.Points++; } }
/// <summary> /// W tej chwili znamy przeciwnika, wiec takze jego heurystyke /// (TODO: czy zmienic na to zeby f heurytycznej zalozyc ze maja taka sama funkcje??) /// </summary> /// <param name="opponent"></param> public void setOpponent(Player opponent) { Opponent = new Player(heuristic, opponent.Color, tileCount); }