private void RestartButton_Click(object sender, EventArgs e) { Game.RestartGame(); Connect4Board.Refresh(); var AIColour = UserPlayer == PlayerColor.Red ? PlayerColor.Black : PlayerColor.Red; AI = new MCTSAI(false, AIColour); if (AIColour == PlayerColor.Red) { AI.MakeMove(Game); } }
private void Connect4Board_Click(object sender, MouseEventArgs e) { var available = GetAvailableInRow(e.Location.X); if (available != null && Game.GameStatus != GameStatusType.BlackWin && Game.GameStatus != GameStatusType.RedWin) { Game.PutInColumn(available.Item2, UserPlayer); Connect4Board.Refresh(); if (Game.GameStatus != GameStatusType.Started && Game.GameStatus != GameStatusType.Initialised) { MessageBox.Show("Koniec gry. Wygrały " + (Game.GameStatus == GameStatusType.BlackWin ? "czerwone" : "zolte") + "."); } else { AI.MakeMove(Game); Connect4Board.Refresh(); if (Game.GameStatus != GameStatusType.Started && Game.GameStatus != GameStatusType.Initialised) { MessageBox.Show("Koniec gry. Wygrały " + (Game.GameStatus == GameStatusType.BlackWin ? "czerwone" : "zolte") + "."); } } } }
private void ChangeToColor() { if (Game.GameStatus == GameStatusType.Started) { DialogResult dialogResult = MessageBox.Show("Gra została już rozpoczęta. Zmiana koloru spowoduje restart gry. Czy chcesz zmienić kolor?", "Gra już rozpoczęta!", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.No) { if (BlackRadioButton.Checked) { RedRadioButton.Checked = !RedRadioButton.Checked; } else { BlackRadioButton.Checked = !BlackRadioButton.Checked; } return; } } if (RedRadioButton.Checked) { UserPlayer = PlayerColor.Red; } if (BlackRadioButton.Checked) { UserPlayer = PlayerColor.Black; } Game.RestartGame(); var AIColour = UserPlayer == PlayerColor.Red ? PlayerColor.Black : PlayerColor.Red; AI = new MCTSAI(false, AIColour); if (AIColour == PlayerColor.Red) { AI.MakeMove(Game); } }