private void buttonSave_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); foreach (GameStateResignAction gsra in resigns) { sb.AppendLine(GameStateResignAction.Serialize(gsra)); } File.AppendAllText("resigns.txt", sb.ToString()); sb = new StringBuilder(); foreach (GameStateDoubleAction gsda in doubles) { sb.AppendLine(GameStateDoubleAction.Serialize(gsda)); } File.AppendAllText("doubles.txt", sb.ToString()); sb = new StringBuilder(); foreach (GameStateTurnAction gsta in turns) { sb.AppendLine(GameStateTurnAction.Serialize(gsta)); } File.AppendAllText("turns.txt", sb.ToString()); sb = new StringBuilder(); foreach (GameStateMoveAction gsma in moves) { sb.AppendLine(GameStateMoveAction.Serialize(gsma)); } File.AppendAllText("moves.txt", sb.ToString()); }
private void buttonDouble_Click(object sender, EventArgs e) { watch.Stop(); GameStateTurnAction gsta = new GameStateTurnAction(currentGameState.Clone(), watch.ElapsedMilliseconds, TurnAction.Double); turns.Add(gsta); textBoxLog.Text += "Turn action added" + " " + watch.ElapsedMilliseconds + "ms." + Environment.NewLine; textBoxLog.SelectionStart = textBoxLog.Text.Length; textBoxLog.ScrollToCaret(); currentGameState.Double(); Render(); this.Refresh(); DoubleResponseHint hint = gnubg.DoubleResponseHint(currentGameState); Thread.Sleep(thinker.TimeOnDoubleOffer(currentGameState, hint)); if (hint.Response == DoubleResponse.Pass) { status = GameStatus.GameOver; return; } if (hint.Response == DoubleResponse.Take) { currentGameState.Take(); } UpdateControls(); }
private void buttonRoll_Click(object sender, EventArgs e) { watch.Stop(); GameStateTurnAction gsta = new GameStateTurnAction(currentGameState.Clone(), watch.ElapsedMilliseconds, TurnAction.Roll); turns.Add(gsta); textBoxLog.Text += "Turn action added" + " " + watch.ElapsedMilliseconds + "ms." + Environment.NewLine; textBoxLog.SelectionStart = textBoxLog.Text.Length; textBoxLog.ScrollToCaret(); buttonRoll.Enabled = false; buttonRoll.Visible = false; currentGameState.SetDice(random.Next(1, 7), random.Next(1, 7)); originalGameState = currentGameState.Clone(); legalPlays = currentGameState.Board.LegalPlays(currentGameState.PlayerOnRoll, currentGameState.Dice); if (legalPlays.Count == 0) { this.Render(); this.Refresh(); legalPlays.Clear(); madeMoves.Clear(); unusedDice.Clear(); currentGameState.ChangeTurn(); Thread.Sleep(1000); UpdateControls(); return; } unusedDice.AddRange(currentGameState.Dice); if (currentGameState.Dice[0] == currentGameState.Dice[1]) { unusedDice.AddRange(currentGameState.Dice); } UpdateControls(); }
public Form1() { List <GameStateDoubleAction> doubles = new List <GameStateDoubleAction>(); List <GameStateTurnAction> turns = new List <GameStateTurnAction>(); List <GameStateMoveAction> moves = new List <GameStateMoveAction>(); foreach (string line in File.ReadAllLines("doubles.txt")) { string s = line.Replace(Environment.NewLine, ""); GameStateDoubleAction a = (GameStateDoubleAction)GameStateDoubleAction.Deserialize(s); doubles.Add(a); Console.WriteLine(a.GameState.ToString() + " " + a.Time); } foreach (string line in File.ReadAllLines("turns.txt")) { string s = line.Replace(Environment.NewLine, ""); GameStateTurnAction a = (GameStateTurnAction)GameStateTurnAction.Deserialize(s); turns.Add(a); } foreach (string line in File.ReadAllLines("moves.txt")) { string s = line.Replace(Environment.NewLine, ""); GameStateMoveAction a = (GameStateMoveAction)GameStateMoveAction.Deserialize(s); moves.Add(a); Console.WriteLine(GameStateMoveAction.Serialize(a)); } thinker = new NeuralThinker(moves, doubles, new GameStateResignAction[] { }, turns); InitializeComponent(); this.MouseClick += new MouseEventHandler(Form1_MouseClick); this.MouseDoubleClick += new MouseEventHandler(Form1_MouseDoubleClick); labelLeftName.Text = "Player"; labelRightName.Text = "Computer"; labelLeftPips.Text = "Pips: 0"; labelRightPips.Text = "Pips: 0"; gnubg.Initialize(); random.Next(); StartNew(); }