/// <summary> /// the computers play /// </summary> private void ComputerPlay() { DisableAllButtons(); uxTextBox.Text = "My Turn."; Update(); for (int i = 0; i < 25000; i++) { UltimateBoard temp = new UltimateBoard(_currentGamePosition); _portionOfGameTree.Simulate(temp); } GameTreeNode t = _portionOfGameTree.GetBestChild(); (int, int, int, int)p = t.Play; _currentGamePosition.Play(p); uxFlowLayoutPanel.Controls[p.Item1].Controls[p.Item2].Controls[p.Item3].Controls[p.Item4].Text = _SymbolOComputer; if (!GameIsover("I")) { _portionOfGameTree = t; foreach ((int, int, int, int)loc in _currentGamePosition.GetAvailablePlays()) { uxFlowLayoutPanel.Controls[loc.Item1].Controls[loc.Item2].Controls[loc.Item3].Controls[loc.Item4].Enabled = true; } uxTextBox.Text = "Your Turn."; } }
/// <summary> /// simulates randomly /// </summary> /// <param name="x">board to simulate</param> /// <returns>returns a float</returns> public static float Simulate(UltimateBoard x) { if (x.IsOver == true) { if (x.IsWon == true) { return(1); } else { return(0.5f); } } else { List <(int, int, int, int)> temp = x.GetAvailablePlays(); int randPlay = _randNum.Next(temp.Count); x.Play(temp[randPlay]); float num = Simulate(x); return(1 - num); } }