コード例 #1
0
ファイル: Game.cs プロジェクト: karim-safin/Balda
        public Game(string startWord, List <Player> players, Rules rules, WordBase wordBase, GamingForm gamingForm)
        {
            State                 = new FieldState(startWord);
            Rules                 = rules;
            Players               = players;
            this.wordBase         = wordBase;
            this.gamingForm       = gamingForm;
            consequtiveTurnPasses = 0;
            secondsTimerCB        = new TimerCallback(timerTick);
            if (Rules.HasTimeLimit == true)
            {
                secondsTimer = new System.Threading.Timer(secondsTimerCB, null, 1000, 1000);
            }

            // now construct the prefix tree
            for (int i = 0; i < prefixTreeMaxSize; ++i)
            {
                isWord[i] = false;
                for (int j = 0; j < 32; ++j)
                {
                    prefixTree[i, j] = -1;
                }
            }
            int firstUnused = 1;

            string[] lines = System.IO.File.ReadAllLines(@"../../word_rus.txt");
            foreach (string word in lines)
            {
                int currentIndex = 0;
                for (int j = 0; j < word.Length; ++j)
                {
                    if (prefixTree[currentIndex, word[j] - 'А'] == -1)
                    {
                        prefixTree[currentIndex, word[j] - 'А'] = firstUnused;
                        currentIndex = firstUnused;
                        ++firstUnused;
                    }
                    else
                    {
                        currentIndex = prefixTree[currentIndex, word[j] - 'А'];
                    }
                    if (j == word.Length - 1)
                    {
                        isWord[currentIndex] = true;
                    }
                }
            }
        }
コード例 #2
0
ファイル: ComputerStrategy.cs プロジェクト: karim-safin/Balda
        public ComputerStrategy(StrategyStrength str, GamingForm gamingForm)
        {
            words = new List <string>();

            this.gamingForm = gamingForm;
            this.str        = str;
            optimalMove     = new Stack <Move>();
            possibleMoves   = new List <Stack <Move> >();
            for (int i = 0; i < prefixTreeMaxSize; ++i)
            {
                isWord[i] = false;
                for (int j = 0; j < 32; ++j)
                {
                    prefixTree[i, j] = -1;
                }
            }
            int firstUnused = 1;

            string[] lines = System.IO.File.ReadAllLines(@"../../word_rus.txt");
            foreach (string word in lines)
            {
                int currentIndex = 0;
                for (int j = 0; j < word.Length; ++j)
                {
                    if (prefixTree[currentIndex, word[j] - 'А'] == -1)
                    {
                        prefixTree[currentIndex, word[j] - 'А'] = firstUnused;
                        currentIndex = firstUnused;
                        ++firstUnused;
                    }
                    else
                    {
                        currentIndex = prefixTree[currentIndex, word[j] - 'А'];
                    }
                    if (j == word.Length - 1)
                    {
                        isWord[currentIndex] = true;
                    }
                }
            }
        }
コード例 #3
0
ファイル: GameCreationForm.cs プロジェクト: karim-safin/Balda
        private void buttonCreateGame_Click(object sender, EventArgs e)
        {
            string startWord = textBoxStartWord.Text.ToUpper();

            if (!wordBase.Contains(startWord))
            {
                MessageBox.Show("Такого слова нет в базе!");
                return;
            }
            int n = playerTypes.Length;
            int m = startWord.Length;

            if (m % 2 == 0)
            {
                MessageBox.Show("Нельзя выбирать слова с чётным количеством букв.");
                return;
            }
            if (!(m * (m - 1) % n == 0))
            {
                MessageBox.Show("С таким словом у игроков будет неодинаковое количество ходов.");
                return;
            }
            List <string> realPlayerNames = new List <string>();
            List <Player> players         = new List <Player>();

            GamingForm gamingForm = new GamingForm(users);

            gamingForm.Owner = this.Owner;

            for (int i = 0; i < playerTypes.Length; ++i)
            {
                if (playerTypes[i].SelectedIndex == 0)
                {
                    string realPlayerName = playerNames[i].Text;
                    if (realPlayerName == "")
                    {
                        MessageBox.Show("Вы не ввели имя игрока!");
                        return;
                    }

                    if (!realPlayerNames.Contains(realPlayerName))
                    {
                        realPlayerNames.Add(realPlayerName);
                    }
                    else
                    {
                        MessageBox.Show("Вы ввели одно или несколько одинаковых имён реальных игроков");
                        return;
                    }

                    players.Add(new Player(new HumanStrategy(gamingForm),
                                           realPlayerName,
                                           playerColors[i],
                                           0));
                }
                else
                {
                    switch (playerTypes[i].SelectedIndex)
                    {
                    case 3:
                    {
                        players.Add(new Player(new ComputerStrategy(StrategyStrength.Hard, gamingForm),
                                               "Сильный ИИ " + computerPlayerNames[i],
                                               playerColors[i],
                                               0));
                    }
                    break;

                    case 2:
                    {
                        players.Add(new Player(new ComputerStrategy(StrategyStrength.Medium, gamingForm),
                                               "Средний ИИ " + computerPlayerNames[i],
                                               playerColors[i],
                                               0));
                    }
                    break;

                    case 1:
                    {
                        players.Add(new Player(new ComputerStrategy(StrategyStrength.Easy, gamingForm),
                                               "Слабый ИИ " + computerPlayerNames[i],
                                               playerColors[i],
                                               0));
                    }
                    break;
                    }
                }
            }
            foreach (string realPlayerName in realPlayerNames)
            {
                if (!users.ContainsKey(realPlayerName))
                {
                    users.Add(realPlayerName, defaultRating);
                }
            }
            // contruct "Game" object somewhere there
            Rules rules = new Rules();

            rules.AllowDiagonal      = checkBoxAllowDiagonal.Checked;
            rules.AllowIntersections = checkBoxAllowIntersections.Checked;
            if ((int)numericUpDownTimeLimit.Value != 0)
            {
                rules.HasTimeLimit = true;
                rules.TimeLimit    = (int)numericUpDownTimeLimit.Value;
            }
            rules.AllowRepeats = checkBoxAllowRepeats.Checked;
            Game game = new Game(startWord, players, rules, wordBase, gamingForm);

            gamingForm.Game = game;
            gamingForm.Show();
            this.Close();
        }
コード例 #4
0
 public HumanStrategy(GamingForm gamingForm)
 {
     this.gamingForm = gamingForm;
 }