public GameData TryMakeMove(Team team, Point pos) { ResponseCode code = Validate(team, pos); if (code != ResponseCode.OK) { return new GameData { Code = code, Field = Field, NextPlayer = team, Updated = Point.Empty } } ; MakeMove(team, pos); bool isWin = _checker.IsWinCondition(pos); if (isWin || _controller.IsFull()) { code = isWin ? ResponseCode.Win : ResponseCode.Draw; State = GameState.GameEnded; } return(new GameData { Code = code, Field = Field, NextPlayer = PlayerTurn, Updated = pos }); }
//private PointScore EvalField(Point p, Team player) //{ // //return _rand.NextDouble(); // Team winner = GetWinner(p); // //File.AppendAllText("output.txt", cgf.RenderAsString(_controller)); // //File.AppendAllText("output.txt", $"Evaluating from point {p} with mult == {mult}\n"); // //File.AppendAllText("output.txt", $"Our team: {_team}, symbol: {cgf.GetSymbolOf(_team)}\n"); // //File.AppendAllText("output.txt", $"Final score: {(winner != Team.None ? (winner == _team ? maxValue : -maxValue) : 0)}\n"); // if (winner != Team.None) // return new PointScore(winner == player ? maxValue : -maxValue, p); // //_controller.SetPos(p, OpponentOf(player)); // //winner = GetWinner(p); // //_controller.SetPos(p, Team.None); // //if(winner == OpponentOf(player)) // // return new PointScore(maxValue, p); // return new PointScore(0, p); // //Dictionary<Point, Direction> processed = new Dictionary<Point, Direction>(); // //int[] counts = new int[_checker.WinLength]; // //for (int y = 0; y < _controller.FieldSize; ++y) // // for (int x = 0; x < _controller.FieldSize; ++x) // // { // // Point current = new Point(x, y); // // Team team = _controller.GetPos(current); // // int offset = team == _team ? 1 : -1; // // //if(_internalField[current.Y,current.X] != team) // // if (_controller.GetPos(current) == Team.None) // // continue; // // //Если текущая клетка была в буфере обработанных, извлекаем, по каким направлениям она была обработана // // Direction processedDirections = Direction.None; // // if (processed.ContainsKey(current)) // // processedDirections = processed[current]; // // //REFACTOR // // foreach (var vector in Vectors) // // { // // if (processedDirections.HasFlag(vector.Key)) // // continue; // // int count = 1; // // Point checking = current + vector.Value; // // while (!_controller.IsOutOfRange(checking) && _controller.GetPos(checking) == team) // // { // // ++count; // // if (processed.ContainsKey(current)) // // processed[current] |= vector.Key; // // else // // processed[current] = vector.Key; // // checking += vector.Value; // // } // // if (count < _checker.WinLength) // // counts[count - 1] += offset; // // //else // // // if (count == 5) // // // return double.PositiveInfinity; // // } // // } // //File.AppendAllText("output.txt", cgf.RenderAsString(_controller)); // //File.AppendAllText("output.txt", $"Our team: {_team}, symbol: {cgf.GetSymbolOf(_team)}\n"); // //File.AppendAllText("output.txt", $"Array cfg: {string.Join(" ", counts)}\n"); // ////return _rand.NextDouble(); // //return counts[0] * Weights[0] + counts[1] * Weights[1] + counts[2] * Weights[2];// + counts[3] * Weights[3]; //} private Team GetWinner(Point winPoint) { if (_checker.IsWinCondition(winPoint)) { return(_controller.GetPos(winPoint)); } return(Team.None); }