/// <summary> /// the function called when we click on a button in the grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void grid_Item_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; int y = (int)btn.GetValue(Grid.RowProperty); int x = (int)btn.GetValue(Grid.ColumnProperty); if (game.IsPlayable(x, y, game.isCurrentPlayerWhite())) { if (game.PlayMove(x, y, game.isCurrentPlayerWhite())) { smanager.Play(game.isCurrentPlayerWhite(), game.lastNumberOfPawnDowned); refreshGrid(); } //game.Evaluate(); if (game.isGameFinished()) { Debug.WriteLine("Game Finished"); if (game.whiteScore > game.blackScore) { MessageBox.Show("Player White win"); } else if (game.whiteScore < game.blackScore) { MessageBox.Show("Player Black win"); } else { MessageBox.Show("Draw"); } game.ResetGame(); refreshGrid(); } else { if (!game.isAnOptionAvailable(0) && !game.isAnOptionAvailable(1)) { Debug.WriteLine("Deadlock, resetting the game"); game.ResetGame(); refreshGrid(); } else if (!game.isAnOptionAvailable(game.getCurrentPlayer() == 0 ? 1 : 0)) { String playerSkipped = game.getCurrentPlayer() == 0 ? "black" : "white"; Debug.WriteLine("No option available, skipping " + playerSkipped + " turn"); } else { game.changePlayer(); refreshGrid(); } } } }