Ejemplo n.º 1
0
    public void Score3_SingleDoubleBonus_Expired_Score3()
    {
        var sut = new StandardScoreCalculator();

        var sequence = new LinkedList <ISquarePiece>();

        sequence.AddLast(GetStandardScore());
        sequence.AddLast(GetStandardScore());
        sequence.AddLast(GetStandardScore());

        sut.AddNewBonus(new ScoreBonus(2, 1));
        sut.CalculateScore(sequence.ToArray());

        // Should be expired now, retry.
        Assert.AreEqual(3, sut.CalculateScore(sequence.ToArray()));
    }
    public void Score0SinglePieces_Score0()
    {
        var sut = new StandardScoreCalculator();

        var sequence = new LinkedList <ISquarePiece>();

        Assert.AreEqual(0, sut.CalculateScore(sequence.ToArray()));
    }
    public void Score1SinglePieces_Bonus0_Score1()
    {
        var sut = new StandardScoreCalculator();

        var sequence = new LinkedList <ISquarePiece>();

        sequence.AddLast(GetStandardScore());

        Assert.AreEqual(1, sut.CalculateScore(sequence.ToArray()));
    }
    public void Score2SinglePieces1Double_Score4()
    {
        var sut = new StandardScoreCalculator();

        var sequence = new LinkedList <ISquarePiece>();

        sequence.AddLast(GetStandardScore());
        sequence.AddLast(GetStandardScore());
        sequence.AddLast(GetDoubleScore());

        Assert.AreEqual(4, sut.CalculateScore(sequence.ToArray()));
    }
Ejemplo n.º 5
0
    public void Score3_SingleDoubleBonus_Score6()
    {
        var sut = new StandardScoreCalculator();

        var sequence = new LinkedList <ISquarePiece>();

        sequence.AddLast(GetStandardScore());
        sequence.AddLast(GetStandardScore());
        sequence.AddLast(GetStandardScore());

        sut.AddNewBonus(new ScoreBonus(2, 1));

        Assert.AreEqual(6, sut.CalculateScore(sequence.ToArray()));
    }
Ejemplo n.º 6
0
        public (SearchResult Result, List <ISquarePiece> Move) GetBestMove(IRestriction restriction)
        {
            this.restriction = restriction;
            startTime        = DateTime.Now;

            IScoreCalculator scoreCalculator = new StandardScoreCalculator();

            bestMove = new List <List <ISquarePiece> >();
            for (int x = 0; x < PieceManager.Instance.NumberOfColumns; x++)
            {
                for (int y = 0; y < PieceManager.Instance.NumberOfRows; y++)
                {
                    var visited     = new List <ISquarePiece>();
                    var currentPath = new List <ISquarePiece>();

                    var piece = PieceManager.Instance.GetPiece(x, y);
                    if (piece == null)
                    {
                        continue;
                    }

                    visited.Add(piece);
                    currentPath.Add(piece);
                    ExplorePiece(piece, visited, currentPath);
                }

                if (TimeExpired)
                {
                    return(SearchResult.TimeOut, new List <ISquarePiece>());
                }
            }

            var filtered = bestMove.Where(x => x.Count >= MinAllowed && !restriction.IsRestrictionViolated(x.ToArray()));

            if (filtered.Count() == 0)
            {
                return(SearchResult.NoMoves, new List <ISquarePiece>());
            }

            var best = filtered.OrderByDescending(x => scoreCalculator.CalculateScore(x.ToArray())).First();


            Debug.Log(string.Join(", ", best.Select(x => x.Position.ToString())));
            return(SearchResult.Success, best.ToList());
        }