Beispiel #1
0
        private async void btn_GameStart_Click(object sender, EventArgs e)
        {
            try
            {
                StartSetting(btn_GameStart);
                Tetris player1 = new Tetris(NewPanel(PanelValue.GetTetrisPanelToPlayer1()),
                                            NewPanel(PanelValue.GetNextBlockPanelToPlayer1()),
                                            lbl_Score, Keyboard.GetPlayer1, 1);
                TetrisAI player2 = TetrisAI.GeneralMode(NewPanel(PanelValue.GetTetrisPanelToPlayer2()),
                                                        NewPanel(PanelValue.GetNextBlockPanelToPlayer2()),
                                                        lbl_2pScore, 2, FileLoad <Weight>(FilePath.Weight));
                _game.PlayerAdd(player1);
                _game.PlayerAdd(player2);
                Size = new Size(690, 870);
                await _game.GameStart();
            }
#pragma warning disable 168
            catch (DirectoryNotFoundException _)
#pragma warning restore 168
            {
                AiNotFound();
            }
#pragma warning disable 168
            catch (FileNotFoundException _)
#pragma warning restore 168
            {
                AiNotFound();
            }
        }
Beispiel #2
0
        public static async Task AlgorithmStart(MetroForm form, Label lbl_Score, Label lbl_BestScore,
                                                Label lbl_Generation,
                                                Label lblBestNum)
        {
            Initialization(form);
            while (true)
            {
                _generation++;
                Players.Clear();

                lbl_Generation.Text = $@"{_generation} 세대";
                for (int i = 0; i < _weights.Length; i++)
                {
                    TetrisAI player = TetrisAI.GeneticMode(_panels[i], lbl_Score, lblBestNum, i + 1,
                                                           _weights[i].Clone());
                    Players.Add(player);
                }

                await GameStart();

                _bestScore         = Math.Max(_bestScore, Players.Max(t => t.Score));
                lbl_BestScore.Text = _bestScore.ToString();
                lbl_Score.Text     = "0";

                MixParents();
            }
        }
Beispiel #3
0
        public static TetrisAI GeneticMode(TetrisPanel tetrisPanel, Label lblScore, Label lblBestNum, int id,
                                           Weight weight)
        {
            TetrisAI t = new TetrisAI(tetrisPanel, null, lblScore, lblBestNum, id, weight);

            t.SetGeneticMode();
            return(t);
        }
Beispiel #4
0
        public static TetrisAI AITestMode(TetrisPanel tetrisPanel, MetroPanel nextBlockPanel, Label lblScore, int id,
                                          Weight weight)
        {
            TetrisAI t = new TetrisAI(tetrisPanel, nextBlockPanel, lblScore, null, id, weight);

            t.SetAiTestMode();
            return(t);
        }
Beispiel #5
0
        private async void btn_AI_Click(object sender, EventArgs e)
        {
            try
            {
                StartSetting(btn_AI);
                _game.PlayerAdd(TetrisAI.AITestMode(NewPanel(PanelValue.GetTetrisPanelToPlayer1()),
                                                    NewPanel(PanelValue.GetNextBlockPanelToPlayer1()),
                                                    lbl_Score, 1, FileLoad <Weight>(FilePath.Weight)));
                Size = new Size(360, 870);
                await _game.GameStart();
            }
#pragma warning disable 168
            catch (DirectoryNotFoundException _)
#pragma warning restore 168
            {
                AiNotFound();
            }
#pragma warning disable 168
            catch (FileNotFoundException _)
#pragma warning restore 168
            {
                AiNotFound();
            }
        }