// Generate random move(s) private void button1_Click(object sender, EventArgs e) { engine = new KaroEngineWrapper(); UpdateGUI(); engine.InsertByXY(5, 4); engine.InsertByXY(6, 4); engine.InsertByXY(7, 4); engine.InsertByXY(8, 4); engine.InsertByXY(9, 4); engine.InsertByXY(5, 5); engine.InsertByXY(6, 5); engine.InsertByXY(7, 5); engine.InsertByXY(8, 5); engine.InsertByXY(9, 5); engine.InsertByXY(5, 6); engine.InsertByXY(6, 6); Application.DoEvents(); int times = int.Parse(textBox1.Text); int moves = 0; DateTime startTijd = DateTime.Now; TimeSpan timeDiff = DateTime.Now - DateTime.Now; for (int i = 0; i < times; i++) { engine.CalculateComputerMove(); moves++; UpdateGUI(); Application.DoEvents(); if (engine.GetGameState() == GameState.GAMEFINISHED) { timeDiff = DateTime.Now - startTijd; ShowWinning(moves, (float)timeDiff.TotalSeconds, false); break; } } timeDiff = DateTime.Now - startTijd; this.txtMessageLog.Text = "Moves:\t" + moves + "\r\n\r\n" + this.txtMessageLog.Text; this.txtMessageLog.Text = "Avarage:\t" + (timeDiff.TotalSeconds / times) + " Seconds \r\n" + this.txtMessageLog.Text; this.txtMessageLog.Text = "Total:\t" + timeDiff.TotalSeconds + " Seconds \r\n" + this.txtMessageLog.Text; }
/// <summary> /// Generates computer move (for multithreading) /// </summary> private void ThreadedMove() { lock (engine) { Player player = engine.GetTurn(); // Sets var for undoAllowed bool undoAllowed = true; if (engine.GetGameState() == KaroEngine.GameState.INSERTION) { undoAllowed = false; } this.computerIsThinking = true; move = engine.CalculateComputerMove(); this.computerIsThinking = false; Point positionFrom = new Point(move[0] % Game1.BOARDWIDTH, move[0] / Game1.BOARDWIDTH); Point positionTo = new Point(move[1] % Game1.BOARDWIDTH, move[1] / Game1.BOARDWIDTH); Point tileFrom = new Point(move[2] % Game1.BOARDWIDTH, move[2] / Game1.BOARDWIDTH); this.PauseDrawing = true; if (this.StartingPieces.Count != 0) { this.selectedStartingPiece = 0; Vector3 red = Color.Tomato.ToVector3(); Vector3 white = Color.White.ToVector3(); for (int i = 0; i < this.StartingPieces.Count; i++) { if (StartingPieces[i].Color.Equals(white) && player == Player.WHITE || StartingPieces[i].Color.Equals(red) && player == Player.RED) { this.selectedStartingPiece = i; break; } } } this.ShowMove(positionFrom, positionTo, tileFrom); this.PauseDrawing = false; startUndoTimer = undoAllowed; moveUndone = false; } }
private void button2_Click(object sender, EventArgs e) { engine = new KaroEngineWrapper(); UpdateGUI(); DateTime startTijd = DateTime.Now; TimeSpan timeDiff = DateTime.Now - DateTime.Now; int white = 0; int red = 0; int draw = 0; bool bdraw = false; int games = int.Parse(textBox2.Text); for (int i = 0; i < games; i++) { newGameToolStripMenuItem_Click(sender, e); int moves = 0; startTijd = DateTime.Now; while (engine.GetGameState() != GameState.GAMEFINISHED) { if (moves >= 180) { bdraw = true; break; } engine.CalculateComputerMove(); moves++; UpdateGUI(); Application.DoEvents(); } textBox2.Text = "" + (int.Parse(textBox2.Text) - 1); if (bdraw) { draw++; } else { if (engine.GetTurn() == Player.WHITE) { red++; } if (engine.GetTurn() == Player.RED) { white++; } } bdraw = false; timeDiff = DateTime.Now - startTijd; ShowWinning(moves, (float)timeDiff.TotalSeconds, bdraw); } this.txtMessageLog.Text = "Draw\t" + draw + "\r\n\r\n" + this.txtMessageLog.Text; this.txtMessageLog.Text = "RED:\t" + red + "\r\n" + this.txtMessageLog.Text; this.txtMessageLog.Text = "WHITE:\t" + white + " \r\n" + this.txtMessageLog.Text; this.txtMessageLog.Text = "Played:\t" + games + "\r\n" + this.txtMessageLog.Text; textBox2.Text = "" + games; }
private void btnDoMove_Click(object sender, EventArgs e) { engine.CalculateComputerMove(); UpdateGUI(); }