/// <summary>Update the settings.</summary> /// <param name="instruction"> /// The instruction of the input line. /// </param> /// <remarks> /// Typically Settings [property] [number/player1/player2] /// </remarks> public void Update(Instruction instruction) { switch (instruction.Action) { case "timeBank": this.TimeBank = instruction.Int32Value; break; case "timePerMove": this.TimePerMove = instruction.Int32Value; break; case "handsPerLevel": this.HandsPerLevel = instruction.Int32Value; break; case "startingStack": this.StartingStack = instruction.Int32Value; break; case "yourBot": this.YourBot = instruction.PlayerTypeValue; break; } }
private static void HandleOpponentReaction(IBot bot, GameState state, Instruction instruction) { if (instruction.Player != state.YourBot) { GameActionType tp; if (Enum.TryParse<GameActionType>(instruction.Action, out tp)) { GameAction action; switch (tp) { case GameActionType.raise: action = GameAction.Raise(instruction.Int32Value); break; case GameActionType.check: action = GameAction.Check; break; case GameActionType.call: action = GameAction.Call; break; case GameActionType.fold: default: action = GameAction.Fold; break; } bot.Reaction(state, action); } } }
/// <summary>Parses a line representing an instruction.</summary> public static Instruction Parse(string line) { if (String.IsNullOrEmpty(line)) { return Instruction.Empty; } if (line.StartsWith("Output from your bot: ")) { return new Instruction() { token0 = "Output", token1 = "from your bot:", token2 = line.Substring(22) }; } if (line.StartsWith("Engine says: ")) { return new Instruction() { token0 = "Engine", token1 = "says:", token2 = line.Substring(13) }; } var splited = line.Split(' '); if (splited.Length != 3) { throw new ArgumentException("The line should describe 3 instruction.", "line"); } if (!ValidToken0.Contains(splited[0])) { throw new ArgumentException("The first token is not valid.", "line"); } var instruction = new Instruction() { token0 = splited[0], token1 = splited[1], token2 = splited[2] }; if (!ValidToken1[instruction.InstructionType].Contains(splited[1])) { throw new ArgumentException("The second token is not valid.", "line"); } var tokenType = InstructionValueType.Int32; TokenTypes.TryGetValue(splited[1], out tokenType); object val = null; var token2 = splited[2]; switch (tokenType) { case InstructionValueType.PlayerType: val = ParsePlayerType(token2); break; case InstructionValueType.Cards: val = ParseCards(token2); break; case InstructionValueType.Zero: val = ParseZero(token2); break; case InstructionValueType.Int32: default: val = ParseInt32(token2); break; } instruction.token2 = val; return instruction; }
/// <summary>Updates the state based on a player instruction.</summary> public void UpdatePlayer(Instruction instruction) { var player = instruction.Player; switch (instruction.Action) { // Nothing need to be done. case "fold": // Nothing need to be done. case "check": break; case "hand": this[player].Hand = instruction.CardsValue; break; case "call": this[player].Call(this.AmountToCall); break; case "raise": this[player].Raise(instruction.Int32Value); break; case "stack": this[player].SetStack(instruction.Int32Value); break; case "post": this[player].Post(player == this.OnButton ? this.SmallBlind : this.BigBlind); break; case "wins": if (this.Result == RoundResult.NoResult) { this.Result = player == PlayerType.player1 ? RoundResult.Player1Wins : RoundResult.Player2Wins; } // if set, and another results follows, its a draw. else { this.Result = RoundResult.Draw; } break; } }
/// <summary>Updates the state based on a match instruction.</summary> public void UpdateMatch(Instruction instruction) { switch (instruction.Action) { case "round": this.Round = instruction.Int32Value; Reset(); break; case "smallBlind": this.SmallBlind = instruction.Int32Value; break; // ignore, should be two times the small blind. case "bigBlind": break; // ignore, is the sum of the pot of player1 and player2. case "maxWinPot": break; // ignore, is difference of the pot of player1 and player2. case "amountToCall": break; case "onButton": this.OnButton = instruction.PlayerTypeValue; break; case "table": this.Table = instruction.CardsValue; break; } }
/// <summary>Updates the state based on an action instruction.</summary> public void UpdateAction(Instruction instruction) { switch (instruction.Action) { case "player1": this.Player1.TimeBank = TimeSpan.FromMilliseconds(instruction.Int32Value); break; case "player2": this.Player2.TimeBank = TimeSpan.FromMilliseconds(instruction.Int32Value); break; } }