private void Calculate() { GC.Collect(); n = Convert.ToInt32(depth_selector.Text.ToString()); currentLocationOfFigures.Clear(); dictionary.Clear(); foreach (var f in figures) { currentLocationOfFigures.Add(new Figures(f.Name, f.positionX, f.positionY, f.Color, f.ImgSource)); } for (int i = 0; i < calculatedSteps.ToArray().Length; i++) { dictionary.Add("A " + i.ToString(), MiniMaxTree.GetNewBoard(currentLocationOfFigures, calculatedSteps[i])); } selectedColor1 = GetSelectedFigure(calculatedSteps[0].startPosX, calculatedSteps[0].startPosY).Color; string selectedColor2; if (selectedColor1 == "white") { selectedColor2 = "black"; } else { selectedColor2 = "white"; } string[] keys = dictionary.Keys.ToArray(); MiniMaxTree tree = new MiniMaxTree(); for (int i = 0; i < (2 * n - 1); i++) { if (i % 2 == 0) { keys = tree.CreateNodes(keys, dictionary, selectedColor2); } else { keys = tree.CreateNodes(keys, dictionary, selectedColor1); } } ChooseBestStep(); }
public ConnectFour(Canvas canvas = null, bool playerStarts = true, int depth = 6) { board = new Stone[6, 7]; for (int i = 0; i < 6; i++) { for (int j = 0; j < 7; j++) { board[i, j] = Stone.Empty; } } _depth = depth; MMT = new MiniMaxTree(this); PlayerStarts = playerStarts; if (!PlayerStarts) { DoBestMove(); } this.g_ = canvas; }