Exemplo n.º 1
0
 public override void Reset()
 {
     if (_hasInitialized)
     {
         SolverParser.IssueCommand(BenzeneCommands.clear_board);
     }
 }
Exemplo n.º 2
0
    public override void OnMyMoveEvent(Board board, MoveChoiceCallback moveChoiceCallback)
    {
        if (!_hasInitialized)
        {
            _callback = moveChoiceCallback;
            return;
        }

        if (_isUsingStandaloneExecutable && board.LastMove == null)
        {
            //Benzene behaviour differs here. The standalones automatically play the first move but in benzene must send command 'genmove b' to get opening move.
            moveChoiceCallback(new Move(new Vector2Int((Settings.BoardDimensions.x) / 2, (Settings.BoardDimensions.y - 1) / 2)));
            return;
        }

        //Ensure states are consistent
        if (board.LastMove != null)
        {
            SolverParser.IssueCommand(BenzeneCommands.play(PlayerColours.White, board.LastMove));
        }

        var moveStr = SolverParser.IssueCommand(BenzeneCommands.genmove(PlayerColours.Black));
        var move    = BenzeneUtil.TryToParseMove(moveStr);

        moveChoiceCallback(move);
    }
Exemplo n.º 3
0
 private void GetMoveInformation()
 {
     _blackMovesStrings = SolverParser.IssueCommand(BenzeneCommands.show_jyblackmoves_list).Trim().Split(' ');
     _numBlackMoves     = (_blackMovesStrings.Length - 1) / 2;
     if (Settings.JYSettings.BlackMovesIndex >= _numBlackMoves)
     {
         Settings.JYSettings.BlackMovesIndex = 0;
     }
 }
Exemplo n.º 4
0
    public override void VisualizeMove()
    {
        if (!_isSelectingMove)
        {
            return;
        }


        base.VisualizeMove();

        if (_visualizedMove == _visualizedPatternForMove)
        {
            return;
        }

        if (_visualizedCounterMove != null)
        {
            if (_visualizedMove == null || _visualizedCounterMove.Location != _visualizedMove.Location)
            {
                _visualization.ClearSelectedMove(_visualizedCounterMove.Location);
                _visualization.ClearAllVCs();
                _virtualConnections.Clear();
            }
        }

        if (_visualizedMove == null)
        {
            _visualizedPatternForMove = null;
            VisualizeBrain();
            return;
        }
        //To get the countermove visualization we must actually play the white move and then get the black respones then undo them.
        SolverParser.IssueCommand(
            BenzeneCommands.play(PlayerColours.White, _visualizedMove));
        _visualizedCounterMove = BenzeneUtil.TryToParseMove(SolverParser.IssueCommand(
                                                                BenzeneCommands.genmove(PlayerColours.Black)));

        VisualizeBrain();

        for (int i = 0; i < 2; i++)
        {
            SolverParser.IssueCommand(
                BenzeneCommands.undo);
        }
        _visualization.SelectMove(_visualizedCounterMove.Location, TileState.Black);
        _visualizedPatternForMove = _visualizedMove;
    }
Exemplo n.º 5
0
    public void Initialize()
    {
        SolverParser.Main(Application.streamingAssetsPath + "/" + _defaultStrategyFile);
        var name         = SolverParser.IssueCommand(BenzeneCommands.name);
        var expectedName = (_isUsingStandaloneExecutable) ? "= jingyang" : "= JY";

        if (expectedName != name)
        {
            Debug.LogError("Failed to start jingyang player. Instead got: " + name);
            return;
        }
        if (!_isUsingStandaloneExecutable)
        {
            //Standalone executables automatically determine boardsize but benzene defaults to 13x13
            SolverParser.IssueCommand(BenzeneCommands.boardsize(new Vector2Int(9, 9)));
        }
        if (_callback != null)
        {
            _callback(new Move(new Vector2Int((Settings.BoardDimensions.x) / 2, (Settings.BoardDimensions.y - 1) / 2)));
        }
    }
Exemplo n.º 6
0
    private void VisualizePatterns()
    {
        _visualization.RemoveAllHighlights();
        var patterns     = SolverParser.IssueCommand(BenzeneCommands.show_jypattern_list).Trim();
        var points       = patterns.Split(' ');
        var location     = Vector2Int.zero;
        var patternIndex = 0;
        var _seenLocals  = new HashSet <int>();

        for (int i = 2; i < points.Length; i += 1)
        {
            if (i % 2 == 0)
            {
                if (points[i].Equals("invalid"))
                {
                    Debug.LogWarningFormat("Player generated invalid move!\n {0}", patterns);
                    i++;
                    continue;
                }

                location = BenzeneUtil.HexPointToLocation(points[i]);
            }
            else
            {
                var ruleInfo = points[i].Split('@');
                var newIndex = int.Parse(ruleInfo[1]);
                int local    = int.Parse(ruleInfo[0]);
                if (_seenLocals.Contains(local))
                {
                    patternIndex++;
                    _seenLocals.Clear();
                }
                _seenLocals.Add(local);
                _visualization.HighlightTile(location, patternIndex, (Settings.JYSettings.RuleNumbers) ? newIndex : -1);
            }
        }
    }
Exemplo n.º 7
0
    private void VisualizeBranches()
    {
        _visualization.RemoveAllHighlights();
        var patterns     = SolverParser.IssueCommand(BenzeneCommands.show_jybranch_list).Trim();
        var points       = patterns.Split(' ');
        var location     = Vector2Int.zero;
        var _seenLocals  = new HashSet <int>();
        var patternIndex = 0;
        var oldBranch    = 0;

        for (int i = 2; i < points.Length; i += 1)
        {
            if (i % 2 == 0)
            {
                if (points[i].Equals("invalid"))
                {
                    Debug.LogWarningFormat("Player generated invalid move!\n {0}", patterns);
                    i++;
                    continue;
                }

                location = BenzeneUtil.HexPointToLocation(points[i]);
            }
            else
            {
                var info         = points[i].Split('@');
                var branchNumber = int.Parse(info[1]);
                if (oldBranch != branchNumber)
                {
                    oldBranch = branchNumber;
                    patternIndex++;
                }
                var ruleNumber = int.Parse(info[0]);
                _visualization.HighlightTile(location, patternIndex, (Settings.JYSettings.RuleNumbers) ? ruleNumber: -1);
            }
        }
    }
Exemplo n.º 8
0
 public override void OnUndoEvent()
 {
     SolverParser.IssueCommand(BenzeneCommands.undo);
 }