Exemplo n.º 1
0
 private bool CanMove(Player player)
 {
     if (!Moves.Any())
     {
         return(Player1State.Player.Equals(player)); //player 1 gets the first move.
     }
     return(!Moves.Peek().Player.Equals(player));
 }
Exemplo n.º 2
0
        public void Add(GotchiMove move)
        {
            if (!Moves.Any(x => string.Equals(x.Name, move.Name, StringComparison.OrdinalIgnoreCase)))
            {
                Moves.Add(move);
            }

            if (Moves.Count > MoveLimit)
            {
                throw new Exception(string.Format("Number of moves added has exceeded the move limit ({0}).", MoveLimit));
            }
        }
Exemplo n.º 3
0
 public bool IsMatch(string move) => Moves.Any(v => move.Equals(v));
Exemplo n.º 4
0
        /// <summary>
        /// Builds all possible right parts for given anchor
        /// </summary>
        /// <param name="partialWord">Word preceding right part</param>
        /// <param name="anchor">Tile from which to build up right part</param>
        /// <param name="boardArray">Board to work with</param>
        /// <param name="validCrossChecks">List of valid cross checks for all empty tiles</param>
        /// <param name="validMovesList">List of valid moves that gets updated</param>
        /// <param name="boardIsHorizontal">Board is untransposed or transposed</param>
        /// <param name="boardBeforeMove">Board before any moves were generated</param>
        /// <param name="tileExtendedWith">Tile that was used to extend the right part</param>
        public void ExtendRight(string partialWord, int[] anchor, BoardTile[,] boardArray, Dictionary <BoardTile,
                                                                                                       List <CharTile> > validCrossChecks, HashSet <GeneratedMove> validMovesList, bool boardIsHorizontal, BoardTile[,] boardBeforeMove,
                                CharTile tileExtendedWith = null)
        {
            //If no tile is present..
            if (boardArray[anchor[0], anchor[1]].CharTile == null)
            {
                //If word up until current tile is valid..
                if (Helper.CheckWordValidity(Dawg, partialWord))
                {
                    //If the move (word, row and column indexes) has not been added already..
                    if (!Moves.Any(m => m.Word.Equals(partialWord)))
                    {
                        //Adds generated move to list of valid moves
                        Dictionary <BoardTile, CharTile> tilesUsed = new Dictionary <BoardTile, CharTile>();

                        //Adds tiles that were used in move
                        for (int i = 0; i < partialWord.Length; i++)
                        {
                            var letter    = partialWord[i];
                            var boardTile = boardArray[anchor[0], anchor[1] - partialWord.Length + i];

                            if (boardTile.CharTile != null)
                            {
                                tilesUsed.Add(boardTile, boardTile.CharTile);
                            }
                            else
                            {
                                tilesUsed.Add(boardTile, tileExtendedWith);
                            }
                        }
                        validMovesList.Add(new GeneratedMove(boardIsHorizontal, anchor[1] - partialWord.Length, anchor[1] - 1, anchor, tilesUsed, boardBeforeMove, RackOfCurrentPlayer));
                    }
                }

                //GEts all letters that can follow current right part word
                HashSet <string> labelsOfDawgEdges = new HashSet <string>(new DawgEdgeEqualityComparer());
                var wordsWithCommonPreffix         = Dawg.MatchPrefix(partialWord);
                foreach (var word in wordsWithCommonPreffix)
                {
                    labelsOfDawgEdges.Add(word.Key.Substring(partialWord.Length));
                }
                foreach (var label in labelsOfDawgEdges)
                {
                    //If the valid letter is in our rack and can be played on the board tile, places it and extends right again
                    //with the newly filled board tile used as anchor if board limit is not reached
                    if (label == "")
                    {
                        continue;
                    }
                    if (RackOfCurrentPlayer.CheckIfTileIsInRack(label[0], true) &&
                        (!validCrossChecks.Any(c => c.Key == boardArray[anchor[0], anchor[1]]) ||
                         validCrossChecks.Any(c => c.Key == boardArray[anchor[0], anchor[1]] && c.Value.Any(x => x.Letter == label[0]))))
                    {
                        CharTile tileToWorkWith = null;
                        if (RackOfCurrentPlayer.CheckIfTileIsInRack(label[0], false))
                        {
                            tileToWorkWith = Dictionary.CharTiles.Where(c => c.Letter == label[0] && c.Score != 0).FirstOrDefault();
                        }
                        else
                        {
                            tileToWorkWith = Dictionary.CharTiles.Where(c => c.Letter == '*').FirstOrDefault();
                        }
                        RackOfCurrentPlayer.SubstractFromRack(tileToWorkWith);
                        boardArray[anchor[0], anchor[1]].CharTile = Dictionary.CharTiles.Where(c => c.Letter == label[0] && c.Score == tileToWorkWith.Score).FirstOrDefault();
                        if (anchor[1] < boardArray.GetLength(1) - 1)
                        {
                            ExtendRight(partialWord + label[0], new int[] { anchor[0], anchor[1] + 1 }, boardArray, validCrossChecks, validMovesList, boardIsHorizontal, boardBeforeMove, tileToWorkWith);
                        }

                        //Otherwise places the tile on the last empty square of the board, checks if its valid and doesn't attempt to extend anymore
                        else
                        {
                            var finalWord = partialWord + boardArray[anchor[0], anchor[1]].CharTile.Letter;
                            if (Helper.CheckWordValidity(Dawg, finalWord))
                            {
                                if (!Moves.Any(m => m.Word.Equals(finalWord)))
                                {
                                    Dictionary <BoardTile, CharTile> tilesUsed = new Dictionary <BoardTile, CharTile>();
                                    for (int i = 0; i < finalWord.Length; i++)
                                    {
                                        var letter    = finalWord[i];
                                        var boardTile = boardArray[anchor[0], anchor[1] - finalWord.Length + 1 + i];
                                        if (boardTile.CharTile != null)
                                        {
                                            tilesUsed.Add(boardTile, boardTile.CharTile);
                                        }
                                        else
                                        {
                                            tilesUsed.Add(boardTile, tileToWorkWith);
                                        }
                                    }
                                    validMovesList.Add(new GeneratedMove(boardIsHorizontal, anchor[1] - finalWord.Length + 1, anchor[1], anchor, tilesUsed, boardBeforeMove, RackOfCurrentPlayer));
                                }
                            }
                        }
                        RackOfCurrentPlayer.AddToRack(tileToWorkWith);
                        boardArray[anchor[0], anchor[1]].CharTile = null;
                    }
                }
            }
            //Otherwise if the current tile is already taken and not empty, used letter from board tile to build to the right again
            else
            {
                var tile = boardArray[anchor[0], anchor[1]].CharTile;
                HashSet <string> labelsOfDawgEdges = new HashSet <string>(new DawgEdgeEqualityComparer());
                var wordsWithCommonPreffix         = Dawg.MatchPrefix(partialWord + tile.Letter);
                foreach (var word in wordsWithCommonPreffix)
                {
                    labelsOfDawgEdges.Add(word.Key.Substring((partialWord + tile.Letter).Length));
                }

                //Extends right if any letters can follow the current right part
                if (labelsOfDawgEdges.Any() && anchor[1] < boardArray.GetLength(1) - 1)
                {
                    ExtendRight(partialWord + tile.Letter, new int[] { anchor[0], anchor[1] + 1 }, boardArray, validCrossChecks, validMovesList, boardIsHorizontal, boardBeforeMove, tile);
                }
            }
        }
Exemplo n.º 5
0
 public bool IsMoving()
 {
     return(Moves.Any(m => m.IsTraitEnabled() && (m.CurrentMovementTypes.HasFlag(MovementType.Horizontal) || m.CurrentMovementTypes.HasFlag(MovementType.Vertical))));
 }
Exemplo n.º 6
0
 public bool IsMate() => !Moves.Any(IsLegal);