예제 #1
0
        public override void MakeFirstMove(PutWordEvent MoveEvent)
        {
            int BestResult = 0;
            int BestStartIndex = 0;
            Dictionary.Dictionary.WordFound BestWord = null;
            Board.Board GameBoard = GameModel.GetBoard();
            Dictionary.Dictionary GameDictionary = GameModel.GetDictionary();

            int CenterIndex = GameBoard.GetBoardSide() % 2 == 0 ? GameBoard.GetBoardSide() / 2 : GameBoard.GetBoardSide() / 2;
            Container CenterRow = GameBoard.FindRow(CenterIndex);

            Dictionary.Dictionary.HeldCharacters HC = new Dictionary.Dictionary.HeldCharacters(GameDictionary.GetDictionaryEncoding());
            HC.Add(Rack.GetTileString());
            Dictionary.Dictionary.AlreadySetLetters ASL = new Dictionary.Dictionary.AlreadySetLetters();
            Dictionary.Dictionary.WordsFound WordsFound = GameDictionary.Find(ASL, HC);

            for(int i = CenterIndex - Configuration.MaxLetterNumber; i <= CenterIndex; ++i)
            {
                Cell TempCell = CenterRow.Get(i);

                foreach(Dictionary.Dictionary.WordFound TempWord in WordsFound)
                {
                    if(TempWord.GetWord().Length > CenterIndex - i)
                    {
                        GameModel.PutTiles(CenterRow, TempCell.GetXColumnCoordinate(), TempWord, Rack);

                        int Result = GameModel.CountWord(CenterRow, TempCell.GetXColumnCoordinate());
                        if(Result > BestResult)
                        {
                            BestResult = Result;
                            BestStartIndex = TempCell.GetXColumnCoordinate();
                            BestWord = TempWord;
                        }

                        GameModel.RemoveTiles(CenterRow, TempCell.GetXColumnCoordinate(), TempWord.GetWord().Length, Rack);
                    }
                }
            }

            if(BestWord == null || BestWord.GetWord().Length < 2) //Jesli nie da sie ulozyc zadnego slowa
            {
                ReplaceTile(null);
                return;
            }

            PointsNumber += BestResult;
            GameModel.PutAndSetTiles(CenterRow, BestStartIndex, BestWord, Rack);
            GameBoard.SetEmpty(false);
            GetNewTiles();
        }
예제 #2
0
        /// <summary>
        /// Metoda dostaje w argumencie wywolania informacje o wszystkich polach na planszy. Jej zadaniem jest odfiltrowanie nowowstawionych kostek, sprawdzenie czy kostki tworza poprawne
        /// slowo i czy zostaly ulozone zgodnie z zasadami gry, a nastepnie dodanie punktow graczowi i wylosowanie dla niego nowych kostek.
        /// </summary>
        /// <param name="MoveEvent"></param>
        /// <returns></returns>
        public override bool MakeMove(PutWordEvent MoveEvent)
        {
            List<Cell> Cells;

            if(MoveEvent != null)
            {
                Cells = MoveEvent.GetBoardCells();
            }
            else
            {
                return false;
            }

            Tuple<List<Cell>, bool> newCellsInfo = GameModel.CheckAndGetNewCells(Cells);
            if(newCellsInfo == null)
            {
                return false;
            }
            if(newCellsInfo.Item1.Count == 0) // Gracz pasuje
            {
                Pass();
                return true;
            }

            Cells = newCellsInfo.Item1;
            bool Vertical = newCellsInfo.Item2;

            if(GameModel.GetBoard().IsEmpty() && Cells.Count != 0) //Jesli pierwszy ruch to sprawdzamy czy slowo jest w srodkowym rzedzie lub kolumnie
            {
                int MiddleCoordinate = GameModel.GetBoard().GetBoardSide() / 2;
                bool MiddleField = false;

                if(Vertical)
                {
                    foreach(Cell TempCell in Cells)
                    {
                        if(TempCell.GetXColumnCoordinate() != MiddleCoordinate)
                        {
                            GameModel.RemoveTiles(Cells);
                            return false;
                        }
                        if(TempCell.GetYRowCoordinate() == MiddleCoordinate)
                        {
                            MiddleField = true;
                        }
                    }
                }
                else
                {
                    foreach(Cell TempCell in Cells)
                    {
                        if(TempCell.GetYRowCoordinate() != MiddleCoordinate)
                        {
                            GameModel.RemoveTiles(Cells);
                            return false;
                        }
                        if(TempCell.GetXColumnCoordinate() == MiddleCoordinate)
                        {
                            MiddleField = true;
                        }
                    }
                }

                if(!MiddleField)
                {
                    GameModel.RemoveTiles(Cells);
                    return false;
                }
            }

            String NewWord;
            int StartIndex;
            Cell StartCell;

            GameModel.PutTiles(Cells);

            if(Vertical)
            {
                NewWord = GameModel.GetWord(GameModel.GetBoard().FindColumn(Cells[0]), Cells[0].GetYRowCoordinate(), Vertical);

                if(NewWord.Length == 1)
                {
                    Vertical = !Vertical;
                    NewWord = GameModel.GetWord(GameModel.GetBoard().FindRow(Cells[0]), Cells[0].GetXColumnCoordinate(), Vertical);
                    StartIndex = GameModel.GetWordInfo(GameModel.GetBoard().FindRow(Cells[0]), Cells[0].GetXColumnCoordinate()).Item2;
                    StartCell = GameModel.GetBoard().GetCell(StartIndex, Cells[0].GetYRowCoordinate());
                }
                else
                {
                    StartIndex = GameModel.GetWordInfo(GameModel.GetBoard().FindColumn(Cells[0]), Cells[0].GetYRowCoordinate()).Item2;
                    StartCell = GameModel.GetBoard().GetCell(Cells[0].GetXColumnCoordinate(), StartIndex);
                }
            }
            else
            {
                NewWord = GameModel.GetWord(GameModel.GetBoard().FindRow(Cells[0]), Cells[0].GetXColumnCoordinate(), Vertical);

                if(NewWord.Length == 1)
                {
                    Vertical = !Vertical;
                    NewWord = GameModel.GetWord(GameModel.GetBoard().FindColumn(Cells[0]), Cells[0].GetYRowCoordinate(), Vertical);
                    StartIndex = GameModel.GetWordInfo(GameModel.GetBoard().FindColumn(Cells[0]), Cells[0].GetYRowCoordinate()).Item2;
                    StartCell = GameModel.GetBoard().GetCell(Cells[0].GetXColumnCoordinate(), StartIndex);
                }
                else
                {
                    StartIndex = GameModel.GetWordInfo(GameModel.GetBoard().FindRow(Cells[0]), Cells[0].GetXColumnCoordinate()).Item2;
                    StartCell = GameModel.GetBoard().GetCell(StartIndex, Cells[0].GetYRowCoordinate());
                }
            }

            if(!GameModel.GetDictionary().Exists(NewWord) || !GameModel.IsMoveCorrect(NewWord, StartCell, Vertical)
                || (!GameModel.GetBoard().IsEmpty() && !IsWordPutCorrect(StartCell, Vertical, NewWord.Length))) //Jesli slowo nie istnieje albo jest wstawione w niepoprawne miejsce albo jego ulozenie powoduje ulozenie niepoprawnych slow
            {
                GameModel.RemoveTiles(Cells);
                return false;
            }

            PointsNumber += GameModel.CountPoints(NewWord, StartCell, Vertical);
            GameModel.SetVisited(Cells);

            Rack.Clear();
            Rack.AddRange(MoveEvent.GetPlayerTiles()); //Aktualizacja tabliczki
            GetNewTiles();
            GameModel.GetBoard().SetEmpty(false);
            return true;
        }
예제 #3
0
 public override void MakeFirstMove(PutWordEvent MoveEvent)
 {
 }
예제 #4
0
        /// <summary>
        /// Procedura wykonywania ruchu przez algorytm gracza komputerowego. Dla kazdego pola, algorytm sprawdza czy można zgodnie z zasadami gry wstawić słowo w taki sposób, że pierwsza jego litera
        /// znajdować będzie się na rozpatrywanym polu. Następnie algorytm wyszukuje najlepiej punktowane słowo i zapisuje je (a także zapisuje informacje o tym, gdzie słowo powinno zostać
        /// umieszczone). Po wykonaniu procedury dla wszystkich pól, algorytm wstawia najlepsze znalezione słowo. Jeśli gracz nie ma możliwości wstawienia słowa w żadne miejsce, wymienia losową kostkę lub 
        /// ustawia flage informujaca ze nie jest w stanie wykonac juz ruchu jesli zestaw kostek jest pusty.
        /// </summary>
        public override bool MakeMove(PutWordEvent MoveEvent)
        {
            int BestResult = 0;
            int BestStartIndex = 0;
            Dictionary.Dictionary.WordFound BestWord = null;
            Container BestContainer = null;

            Board.Board GameBoard = GameModel.GetBoard();
            Dictionary.Dictionary GameDictionary = GameModel.GetDictionary();
            Dictionary.Dictionary.HeldCharacters HC = new Dictionary.Dictionary.HeldCharacters(GameDictionary.GetDictionaryEncoding());
            HC.Add(Rack.GetTileString());

            int MinLength = 0;
            int MaxLength = GameBoard.GetBoardSide();

            foreach(Row TempRow in GameBoard.GetRows())
            {
                for(int i = 0; i < GameBoard.GetBoardSide() - 1; ++i)
                {
                    Cell TempCell = TempRow.Get(i);

                    if(GameModel.IsPositionCorrect(TempCell, false)) //Czy da sie ustawic slowo zaczynajac od tego pola tak, aby bylo to zgodne z regulami gry
                    {
                        MaxLength = GameBoard.GetBoardSide() - TempCell.GetXColumnCoordinate();
                        MinLength = GameModel.GetMinLength(TempCell, false);

                        Dictionary.Dictionary.AlreadySetLetters ASL = new Dictionary.Dictionary.AlreadySetLetters();
                        GameModel.FillAlreadySetLetters(ASL, TempRow, TempCell.GetXColumnCoordinate());

                        Dictionary.Dictionary.WordsFound WordsFound = GameDictionary.Find(ASL, HC);
                        WordsFound = GameModel.FilterWords(WordsFound, MinLength, MaxLength);

                        foreach(Dictionary.Dictionary.WordFound TempWord in WordsFound)
                        {
                            if(GameModel.IsMoveCorrect(TempWord.GetWord(), TempCell, false)) //Czy ustawienie tego slowa nie spowoduje kolizji w drugiej plaszczyznie
                            {
                                GameModel.PutTiles(TempRow, TempCell.GetXColumnCoordinate(), TempWord, Rack);

                                int Result = GameModel.CountPoints(TempWord.GetWord(), TempCell, false);
                                if(Result > BestResult)
                                {
                                    BestResult = Result;
                                    BestStartIndex = TempCell.GetXColumnCoordinate();
                                    BestWord = TempWord;
                                    BestContainer = TempRow;
                                }

                                GameModel.RemoveTiles(TempRow, TempCell.GetXColumnCoordinate(), TempWord.GetWord().Length, Rack);
                            }
                        }
                    }
                }
            }
            foreach(Column TempColumn in GameBoard.GetColumns())
            {
                for(int i = 0; i < GameBoard.GetBoardSide() - 1; ++i)
                {
                    Cell TempCell = TempColumn.Get(i);

                    if(GameModel.IsPositionCorrect(TempCell, true))
                    {
                        MaxLength = GameBoard.GetBoardSide() - TempCell.GetYRowCoordinate();
                        MinLength = GameModel.GetMinLength(TempCell, true);

                        Dictionary.Dictionary.AlreadySetLetters ASL = new Dictionary.Dictionary.AlreadySetLetters();
                        GameModel.FillAlreadySetLetters(ASL, TempColumn, TempCell.GetYRowCoordinate());

                        Dictionary.Dictionary.WordsFound WordsFound = GameDictionary.Find(ASL, HC);
                        WordsFound = GameModel.FilterWords(WordsFound, MinLength, MaxLength);

                        foreach(Dictionary.Dictionary.WordFound TempWord in WordsFound)
                        {
                            if(GameModel.IsMoveCorrect(TempWord.GetWord(), TempCell, true))
                            {
                                GameModel.PutTiles(TempColumn, TempCell.GetYRowCoordinate(), TempWord, Rack);

                                int Result = GameModel.CountPoints(TempWord.GetWord(), TempCell, true);
                                if(Result > BestResult)
                                {
                                    BestResult = Result;
                                    BestStartIndex = TempCell.GetYRowCoordinate();
                                    BestWord = TempWord;
                                    BestContainer = TempColumn;
                                }

                                GameModel.RemoveTiles(TempColumn, TempCell.GetYRowCoordinate(), TempWord.GetWord().Length, Rack);
                            }
                        }
                    }
                }
            }

            if(BestWord == null || BestWord.GetWord().Length < 2) //Jesli nie da sie ulozyc zadnego slowa
            {
                if(GameModel.GetTilesSet().IsEmpty()) //Jesli nie ma juz z czego dobierac
                {
                    Pass();
                }
                else
                {
                    ReplaceTile(null);
                    GameModel.ResetPassCounter();
                }
                return true;
            }
            PointsNumber += BestResult;
            GameModel.PutAndSetTiles(BestContainer, BestStartIndex, BestWord, Rack);
            GetNewTiles();
            return true;
        }
예제 #5
0
 /// <summary>
 /// Wykonanie pierwszego ruchu
 /// </summary>
 public abstract void MakeFirstMove(PutWordEvent MoveEvent);
예제 #6
0
 /// <summary>
 /// Wykonanie ruchu. Zwraca true jesli ruch zostanie wykonany poprawnie 
 /// </summary>
 public abstract bool MakeMove(PutWordEvent MoveEvent);