Esempio n. 1
0
        private void TPLMVL(int i, int jlhThread, Board board)
        {
            double jlhSimulasi      = 0;
            int    panjangPermainan = 0;

            if (radioCR.IsChecked.Value)
            {
                while (board.isEnd() == END_STATE.CONTINUE)
                {
                    if (currentTurn == PLAYER.COMPUTER)
                    {
                        cumulativeTPVL.TreeParallelization a = new cumulativeTPVL.TreeParallelization(jlhThread / 2, wktMove.Value.Value, board.getBoardState(), false);
                        a.setPGLValue();
                        cumulativeTPVL.Node tmp = a.startNMCTS();
                        action(tmp.action.from, tmp.action.to, board);
                    }
                    else
                    {
                        panjangPermainan++;
                        cumulativeTPVL.TreeParallelization a = new cumulativeTPVL.TreeParallelization(jlhThread, wktMove.Value.Value, board.getBoardState(), false);
                        a.setPGLValue();
                        cumulativeTPVL.Node tmp = a.startNMCTS();
                        action(tmp.action.from, tmp.action.to, board);
                        jlhSimulasi += a.getTotalSimulasi();
                    }
                }
            }
            else
            {
                while (board.isEnd() == END_STATE.CONTINUE)
                {
                    if (currentTurn == PLAYER.COMPUTER)
                    {
                        SimpleCumulativeTPVL.TreeParallelization a = new SimpleCumulativeTPVL.TreeParallelization(jlhThread / 2, wktMove.Value.Value, board.getBoardState(), false);
                        a.setPGLValue();
                        SimpleCumulativeTPVL.Node tmp = a.startNMCTS();
                        action(tmp.action.from, tmp.action.to, board);
                    }
                    else
                    {
                        panjangPermainan++;
                        SimpleCumulativeTPVL.TreeParallelization a = new SimpleCumulativeTPVL.TreeParallelization(jlhThread, wktMove.Value.Value, board.getBoardState(), false);
                        a.setPGLValue();
                        SimpleCumulativeTPVL.Node tmp = a.startNMCTS();
                        action(tmp.action.from, tmp.action.to, board);
                        jlhSimulasi += a.getTotalSimulasi();
                    }
                }
            }

            dg.Items.Add(new Result(i + 1, getResult(), jlhSimulasi / panjangPermainan));
        }
Esempio n. 2
0
        private void switchTurn()
        {
            END_STATE tmpResult = this.logicalCDC.isEnd();

            if (tmpResult == END_STATE.BLACK_WIN)
            {
                //MAINKAN SUARANYA
                if (Properties.Settings.Default["Sound"].ToString() == "Enable")
                {
                    Player.Open(new Uri(@"PindahPiece\" + Properties.Settings.Default["EndingSound"].ToString() + ".wav", UriKind.RelativeOrAbsolute));
                    Player.Play();
                }
                MessageBox.Show("BLACK WIN");
                main.newGame();
            }
            else if (tmpResult == END_STATE.RED_WIN)
            {
                //MAINKAN SUARANYA
                if (Properties.Settings.Default["Sound"].ToString() == "Enable")
                {
                    Player.Open(new Uri(@"PindahPiece\" + Properties.Settings.Default["EndingSound"].ToString() + ".wav", UriKind.RelativeOrAbsolute));
                    Player.Play();
                }
                MessageBox.Show("RED WIN");
                main.newGame();
            }
            else if (tmpResult == END_STATE.DRAW)
            {
                //MAINKAN SUARANYA
                if (Properties.Settings.Default["Sound"].ToString() == "Enable")
                {
                    Player.Open(new Uri(@"PindahPiece\" + Properties.Settings.Default["EndingSound"].ToString() + ".wav", UriKind.RelativeOrAbsolute));
                    Player.Play();
                }
                MessageBox.Show("DRAW");
                main.newGame();
            }
            else
            {
                if (this.currentTurn == PLAYER.COMPUTER)
                {
                    this.currentTurn = PLAYER.HUMAN;
                    changeDisable();
                }
                else
                {
                    this.currentTurn = PLAYER.COMPUTER;
                    changeDisable();
                    if (this.tournament == TOURNAMENT.HUMAN_VS_COMPUTER)
                    {
                        Task.Run(() =>
                        {
                            string metode         = Properties.Settings.Default["Metode"].ToString();
                            string fungsiEvaluasi = Properties.Settings.Default["Evaluasi"].ToString();
                            int jlhParallelTask   = int.Parse(Properties.Settings.Default["ParallelTask"].ToString());
                            int moveTime          = int.Parse(Properties.Settings.Default["MoveTime"].ToString());

                            if (metode.Equals("Root"))
                            {
                                if (fungsiEvaluasi.Equals("Cumulative"))
                                {
                                    cumulativeRP.RootParallelization a = new cumulativeRP.RootParallelization(jlhParallelTask, moveTime, this.logicalCDC.getBoardState(), false);
                                    a.setPGLValue();
                                    cumulativeRP.Node tmp = a.startNMCTS();

                                    this.Dispatcher.BeginInvoke((Action)(() =>
                                    {//jalankan
                                        moveByCoding(tmp.action.from, tmp.action.to);

                                        main.tree.Content = new CumulativeTree(a.result, CumulativeTree.METODE.ROOT);
                                        //switchTurn();
                                    }));
                                }
                                else
                                {
                                    SimpleCumulativeRP.RootParallelization a = new SimpleCumulativeRP.RootParallelization(jlhParallelTask, moveTime, this.logicalCDC.getBoardState(), false);
                                    a.setPGLValue();
                                    SimpleCumulativeRP.Node tmp = a.startNMCTS();

                                    this.Dispatcher.BeginInvoke((Action)(() =>
                                    {//jalankan
                                        moveByCoding(tmp.action.from, tmp.action.to);

                                        main.tree.Content = new SimpleTree(a.result, SimpleTree.METODE.ROOT);
                                        //switchTurn();
                                    }));
                                }
                            }
                            else if (metode.Equals("Tree"))
                            {
                                if (fungsiEvaluasi.Equals("Cumulative"))
                                {
                                    cumulativeTP.TreeParallelization a = new cumulativeTP.TreeParallelization(jlhParallelTask, moveTime, this.logicalCDC.getBoardState(), false);
                                    a.setPGLValue();
                                    cumulativeTP.Node tmp = a.startNMCTS();

                                    this.Dispatcher.BeginInvoke((Action)(() =>
                                    {//jalankan
                                        moveByCoding(tmp.action.from, tmp.action.to);

                                        main.tree.Content = new CumulativeTree(a.tree, CumulativeTree.METODE.TREE);
                                        //switchTurn();
                                    }));
                                }
                                else
                                {
                                    SimpleCumulativeTP.TreeParallelization a = new SimpleCumulativeTP.TreeParallelization(jlhParallelTask, moveTime, this.logicalCDC.getBoardState(), false);
                                    a.setPGLValue();
                                    SimpleCumulativeTP.Node tmp = a.startNMCTS();

                                    this.Dispatcher.BeginInvoke((Action)(() =>
                                    {//jalankan
                                        moveByCoding(tmp.action.from, tmp.action.to);

                                        main.tree.Content = new SimpleTree(a.tree, SimpleTree.METODE.TREE);
                                        //switchTurn();
                                    }));
                                }
                            }
                            else
                            {
                                if (fungsiEvaluasi.Equals("Cumulative"))
                                {
                                    cumulativeTPVL.TreeParallelization a = new cumulativeTPVL.TreeParallelization(jlhParallelTask, moveTime, this.logicalCDC.getBoardState(), false);
                                    a.setPGLValue();
                                    cumulativeTPVL.Node tmp = a.startNMCTS();

                                    this.Dispatcher.BeginInvoke((Action)(() =>
                                    {//jalankan
                                        moveByCoding(tmp.action.from, tmp.action.to);

                                        main.tree.Content = new CumulativeTree(a.tree, CumulativeTree.METODE.TREEVL);
                                        //switchTurn();
                                    }));
                                }
                                else
                                {
                                    SimpleCumulativeTPVL.TreeParallelization a = new SimpleCumulativeTPVL.TreeParallelization(jlhParallelTask, moveTime, this.logicalCDC.getBoardState(), false);
                                    a.setPGLValue();
                                    SimpleCumulativeTPVL.Node tmp = a.startNMCTS();

                                    this.Dispatcher.BeginInvoke((Action)(() =>
                                    {//jalankan
                                        moveByCoding(tmp.action.from, tmp.action.to);

                                        main.tree.Content = new SimpleTree(a.tree, SimpleTree.METODE.TREEVL);
                                        //switchTurn();
                                    }));
                                }
                            }
                        });
                    }
                }
            }
        }