예제 #1
0
    public string FindBestTurn()
    {
        var turns = new Stack <Turn>();

        try
        {
            SimulateMoves(originBoard, turns, 2);
        }
        catch (TimeoutException) { }

        XmaxRush.D(maxTurns);

        return(maxTurns.Last().ToString());
    }
예제 #2
0
    public void SimulateMoves(Board board, Stack <Turn> turns, int deep)
    {
        if (turns.Any())
        {
            var score = CalcScore(board, 0);

            if (score > maxScore)
            {
                maxScore  = score;
                NextTurns = maxTurns;
                maxTurns  = turns.ToArray();
                //XmaxRush.D(maxTurns);
                //XmaxRush.D(maxScore);
            }
        }

        if (deep == 0)
        {
            return;
        }

        XmaxRush.AssertTimeout();

        IEnumerable <Turn> turnsToEvaluate;

        if (board.MoveTurn)
        {
            turnsToEvaluate = EnumMoves(board).ToArray();
        }
        else
        {
            turnsToEvaluate = EnumPushes(board);
        }

        foreach (var t in turnsToEvaluate)
        {
            var newBoard = board.Clone();
            t.Apply(newBoard);
            turns.Push(t);
            SimulateMoves(newBoard, turns, deep - 1);
            turns.Pop();
        }
    }