public static GameStateResignAction Deserialize(string s) { string[] ss = s.Split(new char[] { '|' }); GameState gs = GameState.Deserialize(ss[0]); ss = ss[1].Split(' '); int time = int.Parse(ss[0]); ResignResponse response = (ResignResponse)Enum.Parse(typeof(ResignResponse), ss[1]); GameStateResignAction gsra = new GameStateResignAction(gs, time, response); return gsra; }
public static GameStateResignAction Deserialize(string s) { string[] ss = s.Split(new char[] { '|' }); GameState gs = GameState.Deserialize(ss[0]); ss = ss[1].Split(' '); int time = int.Parse(ss[0]); ResignResponse response = (ResignResponse)Enum.Parse(typeof(ResignResponse), ss[1]); GameStateResignAction gsra = new GameStateResignAction(gs, time, response); return(gsra); }
public static string Serialize(GameStateResignAction gsra) { return GameState.Serialize(gsra.GameState) + "|" + gsra.time + " " + gsra.response.ToString(); }
public static string Serialize(GameStateResignAction gsra) { return(GameState.Serialize(gsra.GameState) + "|" + gsra.time + " " + gsra.response.ToString()); }
private void HandleAI() { if (currentGameState.PlayerOnTurn == 1) { if (currentGameState.HasOffer) { } else { if (currentGameState.DiceRolled) { Thread.Sleep(thinker.TimeOnDiceRolled(currentGameState)); List<PlayHint> hints = gnubg.PlayHint(currentGameState, 500); if (hints != null) { TimedPlay play = thinker.TimedPlayOnRoll(currentGameState, hints, GR.Gambling.Backgammon.Venue.VenueUndoMethod.UndoLast); Stack<Move> oppMadeMoves = new Stack<Move>(); //currentGameState.Board.MakePlay(1, hints[0].Play); foreach (TimedMove move in play) { Thread.Sleep(move.WaitBefore); if (move.IsUndo) { Move m = oppMadeMoves.Pop(); currentGameState.Board.UndoMove(1, m); } else { oppMadeMoves.Push(move); currentGameState.Board.MakeMove(1, move); } Render(); this.Refresh(); //this.Invalidate(); Thread.Sleep(move.WaitAfter); } } if (hints == null) Thread.Sleep(1000); Thread.Sleep(500); currentGameState.ChangeTurn(); } else { DoubleHint doubleHint = gnubg.DoubleHint(currentGameState); Thread.Sleep(thinker.TimeOnTurnChanged(currentGameState, doubleHint, null)); if (currentGameState.CanDouble()) { if (doubleHint.Action == DoubleAction.Double) { watch = Stopwatch.StartNew(); DialogResult res = MessageBox.Show("Your opponent doubles..", "Double offer", MessageBoxButtons.YesNo); watch.Stop(); GameState gs = currentGameState.Clone(); gs.Double(); GameStateDoubleAction gsda = new GameStateDoubleAction(gs, watch.ElapsedMilliseconds, (res == DialogResult.Yes) ? DoubleResponse.Take : DoubleResponse.Pass); doubles.Add(gsda); textBoxLog.Text += "Double response added " + gs.OfferType.ToString() + " " + watch.ElapsedMilliseconds + "ms." + Environment.NewLine; textBoxLog.SelectionStart = textBoxLog.Text.Length; textBoxLog.ScrollToCaret(); if (res == DialogResult.Yes) { currentGameState.SetCube(currentGameState.Cube.Value * 2, 0); Render(); this.Refresh(); } else { status = GameStatus.GameOver; } UpdateControls(); return; } } if (!resignOfferMade) { ResignHint resignHint = gnubg.ResignHint(currentGameState, false); if (resignHint.Value != ResignValue.None) { watch = Stopwatch.StartNew(); DialogResult res = MessageBox.Show("Your opponent wants to resign for " + resignHint.Value.ToString(), "Resign offer", MessageBoxButtons.YesNo); watch.Stop(); GameState gs = currentGameState.Clone(); gs.Resign(resignHint.Value); GameStateResignAction gsra = new GameStateResignAction(gs, watch.ElapsedMilliseconds, (res == DialogResult.Yes) ? ResignResponse.Accept : ResignResponse.Reject); resigns.Add(gsra); textBoxLog.Text += "Resign response added " + gs.OfferType.ToString() + " " + watch.ElapsedMilliseconds + "ms." + Environment.NewLine; textBoxLog.SelectionStart = textBoxLog.Text.Length; textBoxLog.ScrollToCaret(); if (res == DialogResult.Yes) { status = GameStatus.GameOver; Render(); this.Refresh(); } else { resignOfferMade = true; } UpdateControls(); return; } } // Roll currentGameState.SetDice(random.Next(1, 7), random.Next(1, 7)); } } UpdateControls(); } }