Esempio n. 1
0
        //Helper function that adds pawn moves blocked and wall placements blocked based on wall given.
        private void PlaceWall(string move)
        {
            WallsPlaced.Add(move);
            if (IsPlayerOneTurn)
            {
                PlayerOneNumWalls--;
            }
            else
            {
                PlayerTwoNumWalls--;
            }

            //When wall is placed need to lookup what pawn moves become invalid.
            List <Move> movesBlocked = DictionaryLookup.PerformPawnBlockLookup(move);

            foreach (Move blockedMove in movesBlocked)
            {
                InvalidPawnMoves.Add(blockedMove);
            }

            List <string> wallsBlocked = DictionaryLookup.PerformWallBlockLookup(move);

            foreach (string blockedWall in wallsBlocked)
            {
                ValidWallPlacements.Remove(blockedWall);
            }
        }
Esempio n. 2
0
 void Start()
 {
     anim = GameObject.Find("Canvas").GetComponent <Animator>();
     text = GetComponent <DictionaryLookup>();
     stop = GetComponent <PlayerMovement>();
     tail = GetComponent <BoardTutorial>();
     //tm = GetComponent<TutorialManager>();
     dpad = GameObject.Find("DPad");
 }
 void Start()
 {
     anim  = GameObject.Find("Canvas").GetComponent <Animator>();
     text  = GetComponent <DictionaryLookup>();
     stop  = GetComponent <PlayerMovement>();
     goi   = GetComponent <GameOverInfo>();
     tail  = GetComponent <BoardWordSnake>();
     adCon = GetComponent <AdController>();
     dpad  = GameObject.Find("DPad");
 }
Esempio n. 4
0
        //Returns a list of moves from the space specified.
        //This is used as a helper function in traversal functions.
        public List <string> GetAdjacentMoves(string space)
        {
            List <string> possibleMoves = new List <string>();

            foreach (string move in DictionaryLookup.PerformAdjacentSpaceLookup(space))
            {
                if (!InvalidPawnMoves.Contains(new Move(space, move)))
                {
                    possibleMoves.Add(move);
                }
            }
            return(possibleMoves);
        }
        /// <summary>
        ///     Creates a <see cref="Lookup{TKey,TElement}" /> from an <see cref="IEnumerable{T}" /> according to a specified key selector function.
        ///     <b>The funtion can return zero, one or several keys for an element.</b>.
        /// </summary>
        /// <remarks>
        ///     The difference with
        ///     <seealso cref="Enumerable.ToLookup{TSource,TKey}(IEnumerable{TSource}, Func{TSource,TKey})" /> is that an
        ///     element can have zero, one or several keys.<br />
        ///     Hence an element can be contained in several groups, if it has several keys.
        /// </remarks>
        /// <typeparam name="T">The type of the elements of <paramref name="source" />.</typeparam>
        /// <typeparam name="TKey">The type of the keys in the result <see cref="Lookup{TKey,TElement}" />.</typeparam>
        /// <param name="source">An <i>IEnumerable&lt;T&gt;</i> to create an hashset from.</param>
        /// <param name="func">A function to extract a sequence of keys from each element.</param>
        /// <returns>An hashset that contains the elements from the input sequence.</returns>
        /// <seealso cref="Enumerable.ToLookup{TSource,TKey}(IEnumerable{TSource}, Func{TSource,TKey})" />
        public static ILookup <TKey, T> ToMultiKeyLookup <T, TKey>(this IEnumerable <T> source, Func <T, IEnumerable <TKey> > func)
        {
            Contract.Requires(source != null, "seq must not be null");
            Contract.Requires(func != null, "func must not be null");
            Contract.Ensures(Contract.Result <ILookup <TKey, T> >() != null, "returned lookup object is not null");

            Debug.Assert(source != null);

            var dictionaryLookup = new DictionaryLookup <TKey, T>();

            foreach (var elem in source)
            {
                var keys = func(elem);

                if (keys == null)
                {
                    continue;
                }

                foreach (var key in keys)
                {
                    IEnumerable <T> tempEnumerable;

                    if (!dictionaryLookup.TryGetValue(key, out tempEnumerable))
                    {
                        // A single sequence is added first, and if several elements share the same key we transform the single sequence into a list.
                        // This is an optimisation because a single sequence is cheaper than a List<T>,
                        // and we hope that most keys are not not shared by several elements.
                        dictionaryLookup.Add(key, elem.ToEnumerable());

                        continue;
                    }

                    var list = tempEnumerable as List <T>;

                    if (list != null)
                    {
                        list.Add(elem);

                        continue;
                    }

                    list = new List <T> {
                        tempEnumerable.First(), elem
                    };
                    dictionaryLookup[key] = list;
                }
            }

            return(dictionaryLookup);
        }
Esempio n. 6
0
        //This returns all walls adjacent to the wall move made in
        public List <WallDiffNode> GetChildren()
        {
            List <WallDiffNode> children      = new List <WallDiffNode>();
            List <string>       adjacentWalls = DictionaryLookup.PerformWallsOfInterestLookup(MoveMade);

            foreach (string wall in adjacentWalls)
            {
                AIBoard tempBoard = new AIBoard(Board);
                tempBoard.MakeMove(wall);
                if (BoardAnalysis.CheckPathExists(tempBoard, true) && BoardAnalysis.CheckPathExists(tempBoard, false))
                {
                    children.Add(new WallDiffNode(this, wall));
                }
            }
            return(children);
        }
Esempio n. 7
0
        //Pruning function used select only walls adjacent to walls or adjacent to pawns.
        private void SetNodesOfInterest(ref HashSet <string> moves)
        {
            int p1Column = Board.GetPlayerOnePos()[0];                  //Ascii column Value of a-i
            int p1Row    = Board.GetPlayerOnePos()[1];                  //Ascii row Value of 1-9

            int           p2Column        = Board.GetPlayerTwoPos()[0]; //Ascii column Value of a-i
            int           p2Row           = Board.GetPlayerOnePos()[1]; //Ascii row Value of 1-9
            List <string> wallsOfInterest = new List <string>();

            List <int> columnsOfInterest = new List <int> {
                p1Column - 1, p1Column, p1Column + 1, p2Column - 1, p2Column, p2Column + 1
            };
            List <int> rowsOfInterest = new List <int> {
                p1Row - 1, p1Row, p1Row + 1, p2Row - 1, p2Row, p2Row + 1
            };
            List <string> toBeRemoved = new List <string>();

            foreach (string wall in Board.GetWallsPlaced())
            {
                wallsOfInterest.AddRange(DictionaryLookup.PerformWallsOfInterestLookup(wall));
            }

            foreach (string move in moves)
            {
                if (!columnsOfInterest.Contains(move[0]) || !rowsOfInterest.Contains(move[1]))
                {
                    if (!wallsOfInterest.Contains(move))
                    {
                        toBeRemoved.Add(move);
                    }
                }
            }

            foreach (string move in toBeRemoved)
            {
                moves.Remove(move);
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of <see cref="PolishStemmer"/>.
 /// </summary>
 public PolishStemmer()
 {
     lookup = new DictionaryLookup(dictionary);
 }