private void Button_Click(object sender, RoutedEventArgs e) // GRAJ { Grid_GameBoard_Loaded(sender, e); if (cbPlayType.SelectedIndex == 0) // Aga { Grid_GameBoard.IsEnabled = true; GameBoard._p2H = cbP2H.SelectedIndex; } else { Grid_GameBoard.IsEnabled = true; GameBoard._p1H = cbP1H.SelectedIndex; GameBoard._p2H = cbP2H.SelectedIndex; var sw2 = new Stopwatch(); sw2.Start(); GameBoard.MakeMove(MinMax.FindBestMove(GameBoard, GameBoard.Player == Player.P1 ? DepthP1 : DepthP2, GameBoard.Player == Player.P2), GameBoard.Player); sw2.Stop(); MoveTimesP1.Add(sw2.Elapsed); } }
private void Disc_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (!(sender is Ellipse)) { return; } Ellipse disc = sender as Ellipse; Position pos = disc.Tag as Position; if (cbPlayType.SelectedIndex == 0) { GameBoard.MakeMove(pos.Column, Player.P1); } else { sw2 = new Stopwatch(); sw2.Start(); GameBoard.MakeMove(MinMax.FindBestMove(GameBoard, GameBoard.Player == Player.P1 ? DepthP1 : DepthP2, GameBoard.Player == Player.P2), GameBoard.Player); MoveTimesP1.Add(sw2.Elapsed); } }
private void GameBoard_PlayerMoved(Position pos, bool player) { Ellipse ellipse = GetEllipse(pos); if (ellipse == null) { return; } SetColor(ellipse, (player ? 1 : 2)); RemoveEvents(ellipse); if (cbPlayType.SelectedIndex == 1) { Grid_GameBoard.Measure(new Size(505, 254)); } if (GameBoard.Player1ExistingAnswers > 0) { var P1Median = Median(MoveTimesP1); var P2Median = Median(MoveTimesP2); // Player 1 wins! MessageBox.Show($"Player 1 wins! \nŚredni czas ruchu P1: {P1Median}\nŚredni czas ruchu P2: {P2Median}"); foreach (var child in Grid_GameBoard.Children) { Ellipse remove = child as Ellipse; RemoveEvents(remove); } return; } else if (GameBoard.Player2ExistingAnswers > 0) { var P1Median = Median(MoveTimesP1); var P2Median = Median(MoveTimesP2); // Player 2 wins! MessageBox.Show($"Player 2 wins! \nŚredni czas ruchu P1: {P1Median}\nŚredni czas ruchu P2: {P2Median}"); foreach (var child in Grid_GameBoard.Children) { Ellipse remove = child as Ellipse; RemoveEvents(remove); } return; } if (GameBoard.GetAvailableMoves().Count == 0) { var P1Median = Median(MoveTimesP1); var P2Median = Median(MoveTimesP2); // Player 2 wins! MessageBox.Show($"Draw! \nŚredni czas ruchu P1: {P1Median}\nŚredni czas ruchu P2: {P2Median}"); } sw2.Stop(); if (GameBoard.Player != Player.P1) // Computer's turn { var sw = new Stopwatch(); sw.Start(); GameBoard.MakeMove(MinMax.FindBestMove(GameBoard, GameBoard.Player == Player.P1 ? DepthP1 : DepthP2, GameBoard.Player == Player.P2), GameBoard.Player); sw.Stop(); MoveTimesP2.Add(sw.Elapsed); } }