Ejemplo n.º 1
0
    // Clones BoardState and removes graphics
    public MoveSuggestor CloneBoard()
    {
        Board createdBoard = Instantiate(board);

        createdBoard.RemoveGraphics();
        MoveSuggestor moveSuggestor = createdBoard.game.currentPlayer.GetComponent <MoveSuggestor>();

        return(moveSuggestor);
    }
Ejemplo n.º 2
0
    public void TryNextMove()
    {
        Action action = actionsToTry[0];

        actionsToTry.RemoveAt(0);
        Board createdBoard = Instantiate(board);
        int   actionScore  = createdBoard.game.currentPlayer.GetScoreIncreaseForRegularPlayer(action);

        actionPathLookup[maxID] = new ActionPath(action, actionScore, GetPlayerID(), depth, board.game.round);

        // Branching
        MoveSuggestor branch    = GetMoveSuggestorFor(createdBoard);
        int           alphaDown = bestActionPath.CalculateAlpha(createdBoard.game.currentPlayer.ID);

        branch.StartProcessing(this, maxDepth, depth, ID: maxID, alpha: alphaDown);
        maxID++;
        startedSubtasks++;
    }
Ejemplo n.º 3
0
    // result: Best Action-Score pair on the called Board
    public void AICallback(ActionPath result, MoveSuggestor ms, int tested, int all)
    {
        ScoredAction branchBestSoFar = actionPathLookup[ms.ID].actions[0];

        ActionPath actionPathToTest = result.AppendAtFront(branchBestSoFar);

        if (pruningOn && pruneThisRound && !branchBestSoFar.Invalid)
        {
            if (actionPathToTest.GetValueFor(GetPlayerID()) >= alpha)
            {
                actionsToTry.Clear();
            }
        }
        bestActionPath = bestActionPath.GetIfBetter(actionPathToTest, GetPlayerID(), this);
        startedSubtasks--;

        // Info
        finished++;
        this.tested += tested;
        this.all    += all;
    }
Ejemplo n.º 4
0
    public ScoredAction GetIfBetter(ScoredAction scoredAction, MoveSuggestor invoker)
    {
        if (Invalid)
        {
            return(scoredAction);
        }
        if (scoredAction.Invalid)
        {
            return(this);
        }

        if (Score > scoredAction.Score)
        {
            return(this);
        }
        else
        {
            // If the Actions are identical
            if (Score == scoredAction.Score)
            {
                ScoredAction randomChoice = Random.Range(0, 2) == 0 ? this : scoredAction;

                // Priorities, Rules
                if (Action.IsPass())
                {
                    return(randomChoice);
                }
                if (Action.Move.GetMoveType(invoker.board) == MoveType.Capture)
                {
                    return(this);    // Capture if possible
                }
                return(randomChoice);
            }
            return(scoredAction);
        }
    }
Ejemplo n.º 5
0
 public override void AICallback(ActionPath result, MoveSuggestor ms, int tested, int all)
 {
     base.AICallback(result, ms, tested, all);
     MakeAction(result.actions[0].Action);
 }
Ejemplo n.º 6
0
 public bool IsDifferentPlayer(MoveSuggestor ms)
 {
     return(GetPlayerID() != ms.GetPlayerID());
 }