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)); }
static void testParallelSrVl() { for (int xy = 0; xy < 1; xy++) { Console.WriteLine(xy + " uuuuuu"); time = new Stopwatch(); time.Start(); Board board = new Board(); board.flip(0, 0); SimpleTPVL.DeterministicNode.side = board.sideToMove; SimpleTPVL.DeterministicNode b = new SimpleTPVL.DeterministicNode(board.getBoardState(), null, Constant.NONE, Constant.NONE); double x = 0; int u = 0; List <SimpleTPVL.Node> visited = new List <SimpleTPVL.Node>(); SimpleTPVL.Node cur = b; visited.Add(cur); cur.expand(); //cur.updateStatus(cur.rollOut(cur)); object a = new object(); ParallelOptions po = new ParallelOptions(); po.MaxDegreeOfParallelism = 100; List <string> threadid = new List <string>(); Parallel.For(0, 4000, po, i => { //lock (a) //{ // bool found = false; // foreach (string y in threadid) // { // if (y == Thread.CurrentThread.ManagedThreadId.ToString()) // { // found = true; // break; // } // } // if (!found) // { // threadid.Add(Thread.CurrentThread.ManagedThreadId.ToString()); // } //} u++; Console.WriteLine(u); b.selectAction(); //lock (a) //{ // while (!(cur.isLeaf())) // { // cur = cur.select(); // visited.Add(cur); // if (cur is TP.NondeterministicNode) // { // if (((TP.NondeterministicNode)cur).selected != null) // { // cur = ((TP.NondeterministicNode)cur).selected; // } // else // { // cur = ((TP.NondeterministicNode)cur.select()).selected; // } // visited.Add(cur); // } // } // cur.expand(); //} //double value = cur.rollOut(cur); //foreach (TP.Node node in visited) //{ // node.updateStatus(value); //} //lock (a) //{ // x +=Node.s; //} }//; ); //foreach (string y in threadid) //{ // Console.WriteLine(y); //} //for (int i = 0; i < 2001; i++) //{ // Console.WriteLine(i); // b.selectAction(cur); // Console.WriteLine(i); // x += Node.s; //}//; time.Stop(); SimpleTP.Node.PGL = x / 500; Console.WriteLine("PGL:" + SimpleTP.Node.PGL); Console.WriteLine(time.Elapsed.TotalSeconds); } }
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(); })); } } }); } } } }