void tempBtn_Click(object sender, RoutedEventArgs e) { btnPass.Focus(); if (!(playerPass)) { if (gameStarted) { if (((Button)sender).Background == Brushes.BurlyWood) { tempString = ((Button)sender).Name.Split(new Char[] { '_' }); if (currentTurn == 1) { ((Button)sender).Background = Brushes.White; boardConfiguration[Convert.ToInt16(tempString[1]), Convert.ToInt16(tempString[2])] = currentTurn; //UPDATE BOARD AFTER CAPTURE boardConfiguration = boardOps.captureCoins(boardConfiguration, currentTurn); //UPDATE STATS lblTime.Content = "LAST MOVE TIME : " + moveTime.Elapsed.Seconds + " SEC."; lblLastMove.Content = "LAST MOVE : " + tempString[1] + "," + tempString[2]; tempCuts = boardOps.returnCuts(); //UPDATE GUI if (tempCuts != null) { for (int loopCount = 0; loopCount < tempCuts.Count; loopCount++) { ((Button)tilesDictionary[tempCuts[loopCount].X + "_" + tempCuts[loopCount].Y]).Background = Brushes.BurlyWood; } } //CHANGE TURN lblTurn.Content = "CURRENT TURN : COMPUTER (THINKING...)"; currentTurn = 2; //COMPUTER PLAYS MCTS computerPlay = new MCTS(boardSize, boardConfiguration); computerWorker.RunWorkerAsync(computerPlay); } } } } else { //CHANGE TURN lblTurn.Content = "CURRENT TURN : COMPUTER (THINKING...)"; currentTurn = 2; //COMPUTER PLAYS MCTS computerPlay = new MCTS(boardSize, boardConfiguration); computerWorker.RunWorkerAsync(computerPlay); } }
private node playNextAction(node currentNode, int currentTurn) { node tempNode = new node(); int actionCount = 0; tempNode.nodeNumber = currentNodeNumber; tempNode.parentNode = currentNode; currentNodeNumber += 1; tempNode.boardConfig = new int[BOARDSIZE, BOARDSIZE]; copyArray(currentNode.boardConfig, tempNode.boardConfig); bool played = false; for (int i = 0; i < BOARDSIZE; i++) { for (int j = 0; j < BOARDSIZE; j++) { if ((currentNode.boardConfig[i, j] == 0) && (isLiberalMove(i, j, currentNode.boardConfig, currentTurn))) { if (actionCount > currentNode.childNodes.Count - 1) { tempNode.boardConfig[i, j] = currentTurn; tempNode.moveX = i; tempNode.moveY = j; played = true; break; } actionCount += 1; } } if (played) { break; } } if (played) { copyArray(boardOps.captureCoins(tempNode.boardConfig, currentTurn), tempNode.boardConfig); tempNode.availableActions = getAvailableActions(tempNode); if (currentTurn == 1) { tempNode.nextPlayer = 2; } else { tempNode.nextPlayer = 1; } return(tempNode); } else { return(null); } }