private void cvBoard_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var mode = (Mode)ddlMode.SelectedDdlItem().Index; var pos = e.GetPosition(cvBoard); if (mode == Mode.Edit) { _gameBoard.EditField(pos); } else if (mode == Mode.TwoPlayers && _gameBoard.IsFieldEmpty(pos)) { _gameBoard.MakeMove(pos); } else if (mode == Mode.PlayerVsRandomAi && _gameBoard.IsFieldEmpty(pos)) { _gameBoard.MakeMove(pos); _gameBoard.MakeRandomMove(); // if (_gameBoard.GameState.Result() == GameResult.Unfinished) wewnątrz } else if (mode == Mode.PlayerVsNNAi && _gameBoard.IsFieldEmpty(pos)) { if (_nnHowToPlayX == null) { Dispatcher.Invoke(() => this.ShowMessageAsync("Error occured", "You need to train Neural network how to play first")); return; } var prevSymbol = _gameBoard.MakeMove(pos); var currSymbol = TicTacToeGame.Opposite(prevSymbol); if (currSymbol != S.X) // trzeba użyć odwrotnej planszy, bo sieć jest nauczona grać iksem { var invertedBoard = new TicTacToeBoard(); invertedBoard.Create(new Canvas { Width = cvBoard.Width, Height = cvBoard.Height }); invertedBoard.GameState = _gameBoard.GameState.Opposite(); invertedBoard.MakeNNMove(prevSymbol, _nnHowToPlayX); // prevSymbol to odwrotność obecnego _gameBoard.GameState = invertedBoard.GameState.Opposite(); _gameBoard.NextSymbol(); // zmieniamy ręcznie na krzyżyk, bo ruch był zrobiony na odwrotnej planszy, więc normalna go nie zarejestrowała } else { _gameBoard.MakeNNMove(currSymbol, _nnHowToPlayX); } } lblGameStatus.Content = _gameBoard.GameState.ResultString; }