示例#1
0
 public void Init(GameView view, Board board, Timer timer, MoveFinder moveFinder)
 {
     View        = view;
     _board      = board;
     _timer      = timer;
     _moveFinder = moveFinder;
     InternalInit();
 }
示例#2
0
        private IEnumerable <Move> FindMoves(IEnumerable <char> letters, WordList list)
        {
            Board board = CreateBoard(list);

            Console.WriteLine(board.ToString());
            Hand       hand   = CreateHand(letters);
            MoveFinder finder = new MoveFinder(board, hand, list);

            return(finder.FindMoves());
        }
示例#3
0
    /*
     * Saves to inRange set of nodes that are in range of this action. Then adds to its hexes indicators for users as child objects with different color.
     */

    public override void OnSelect(Character character, Hex hex)
    {
        inRange = MoveFinder.FindNodesInRange(hex.GetComponent <Node>(), range);
        foreach (Node node in inRange)
        {
            Transform indicator = Instantiate(hexPrefab, node.transform, true) as Transform;
            indicator.position = node.transform.position;
            indicator.GetComponent <Renderer>().material = material;
        }
    }
示例#4
0
        public void FindMovesStartingMovesTest()
        {
            var words = WordList.Load(new string[] { "cat" });

            board = Board.InitiliseBoard(words);
            Hand       hand   = new Hand("cat");
            MoveFinder finder = new MoveFinder(board, hand, words);
            var        moves  = finder.FindMoves().ToList();

            Assert.AreEqual(6, moves.Count);
        }
示例#5
0
    /*
     * If clicked hex is in range moves character on it.
     *
     * @character       character to move
     * @hex             hex to move on
     *
     * @return bool     returns true if operation was successful or false if not
     */

    public override bool Use(Character character, Hex hex)
    {
        MoveFinder.FindNodesInRange(character.GetComponentInParent <Hex>().GetComponent <Node>(), range);
        if (hex.GetComponent <Node>().distance != 0)
        {
            Debug.Log("ID " + character.id + " moved: " + hex.GetComponent <Node>().position.ToString());
            character.transform.SetParent(hex.transform, false);
            return(true);
        }
        Debug.LogWarning("FAILURE! ID " + character.id + " moved: " + hex.GetComponent <Node>().position.ToString());
        return(false);
    }
示例#6
0
        public void FindMovesOrderTest()
        {
            var words = WordList.Load(new string[] { "cat", "fish", "catfish" });

            board = Board.InitiliseBoard(words);
            board.GetCell(7, 4).Letter = 'a';
            Hand       hand   = new Hand("ctfish");
            MoveFinder finder = new MoveFinder(board, hand, words);
            var        moves  = finder.FindMoves().ToList();

            Assert.AreEqual(4, moves.Count);
            // Catfish will get more points then cat.
            Assert.AreEqual("catfish", moves[0].Word);
            Assert.AreEqual("catfish", moves[1].Word);
            Assert.AreEqual("cat", moves[2].Word);
            Assert.AreEqual("cat", moves[3].Word);
        }
示例#7
0
        public void FindMovesFindSimpleHorozontalMoveTest()
        {
            var words = WordList.Load(new string[] { "cat", "zap" });

            board = Board.InitiliseBoard(words);
            board.GetCell(7, 4).Letter = 'z';
            board.GetCell(7, 5).Letter = 'a';
            board.GetCell(7, 6).Letter = 'p';
            Hand       hand   = new Hand("ct");
            MoveFinder finder = new MoveFinder(board, hand, words);
            var        moves  = finder.FindMoves().ToList();

            Assert.AreEqual(1, moves.Count);
            var catMove = moves[0];

            Assert.AreEqual("cat", catMove.Word);
            Assert.AreEqual(MoveOrientation.HORIZONTAL, catMove.Orientation);
            Assert.AreEqual(5, catMove.Row);
            Assert.AreEqual(6, catMove.Column);
        }
示例#8
0
        public void FindMovesHorozontalDontCheckExistingWordsTest()
        {
            var words = WordList.Load(new string[] { "cat" });

            board = Board.InitiliseBoard(words);
            // Existing word (zap) not present in word list, should still form cat
            board.GetCell(7, 4).Letter = 'z';
            board.GetCell(7, 5).Letter = 'a';
            board.GetCell(7, 6).Letter = 'p';
            Hand       hand   = new Hand("ct");
            MoveFinder finder = new MoveFinder(board, hand, words);
            var        moves  = finder.FindMoves().ToList();

            Assert.AreEqual(1, moves.Count);
            var catMove = moves[0];

            Assert.AreEqual("cat", catMove.Word);
            Assert.AreEqual(MoveOrientation.HORIZONTAL, catMove.Orientation);
            Assert.AreEqual(5, catMove.Row);
            Assert.AreEqual(6, catMove.Column);
        }
        private IEnumerable <Move> FindMoves(Board board, Hand hand, WordList list)
        {
            MoveFinder finder = new MoveFinder(board.ThrowIfNull("board"), hand.ThrowIfNull("hand"), list.ThrowIfNull("list"));

            return(finder.FindMoves());
        }