コード例 #1
0
        private static Response PerformBet2(dynamic form)
        {
            var       json      = JObject.Parse(form["game_state"]);
            GameState gameState = json.ToObject <GameState>();

            Console.Error.WriteLine("My bet index: " + gameState.bet_index);

            var bet      = PokerPlayer.BetRequest(gameState).ToString();
            var betBytes = Encoding.UTF8.GetBytes(bet);
            var response = new Response
            {
                ContentType = "text/plain",
                Contents    = s => s.Write(betBytes, 0, betBytes.Length),
                StatusCode  = HttpStatusCode.OK
            };

            return(response);
        }
コード例 #2
0
        public MainModule()
        {
            Get ["/"] = _ => {
                var contentBytes = Encoding.UTF8.GetBytes("OK");
                var response     = new Response {
                    ContentType = "text/plain",
                    Contents    = s => s.Write(contentBytes, 0, contentBytes.Length),
                    StatusCode  = HttpStatusCode.OK
                };
                return(response);
            };

            Post ["/"] = parameters => {
                var    form   = Request.Form;
                string action = form ["action"];
                switch (action)
                {
                case "bet_request":
                {
                    return(PerformBet2(form));
                }

                /*
                 *
                 * Showdown
                 * This action is called at the end of each round. The game state document is sent,
                 * but this time the hole cards of the opponents are also included if those cards were revealed during showdown.
                 *
                 * The player frameworks should define a "showdown" void method in the Player class (or a similar construct). When the action
                 * is called, it should be delegated to this method. This method should be changed by teams to implement learning algorithms.
                 * The string returned is not used.
                 *
                 *  */
                case "showdown":
                {
                    var json = JObject.Parse(form ["game_state"]);
                    PokerPlayer.ShowDown(json);
                    var showDownBytes = Encoding.UTF8.GetBytes("OK");
                    var response      = new Response {
                        ContentType = "text/plain",
                        Contents    = s => s.Write(showDownBytes, 0, showDownBytes.Length),
                        StatusCode  = HttpStatusCode.OK
                    };
                    return(response);
                }

                case "version":
                {
                    var versionBytes = Encoding.UTF8.GetBytes(PokerPlayer.VERSION);
                    return(new Response {
                            ContentType = "text/plain",
                            Contents = s => s.Write(versionBytes, 0, versionBytes.Length),
                            StatusCode = HttpStatusCode.OK
                        });
                }

                case "check":
                {
                    var contentBytes = Encoding.UTF8.GetBytes("OK");
                    var response     = new Response {
                        ContentType = "text/plain",
                        Contents    = s => s.Write(contentBytes, 0, contentBytes.Length),
                        StatusCode  = HttpStatusCode.OK
                    };
                    return(response);
                }

                default:
                    var bytes = Encoding.UTF8.GetBytes("Not an allowed action or request");
                    return(new Response {
                        ContentType = "text/plain",
                        Contents = s => s.Write(bytes, 0, bytes.Length),
                        StatusCode = HttpStatusCode.BadRequest
                    });
                }
            };
        }
コード例 #3
0
        public MainModule()
        {
            Get ["/"] = _ => {
                var contentBytes = Encoding.UTF8.GetBytes("OK");
                var response     = new Response {
                    ContentType = "text/plain",
                    Contents    = s => s.Write(contentBytes, 0, contentBytes.Length),
                    StatusCode  = HttpStatusCode.OK
                };
                return(response);
            };

            Post ["/"] = parameters => {
                var    form   = Request.Form;
                string action = form ["action"];
                switch (action)
                {
                case "bet_request":
                {
                    var json       = JObject.Parse(form ["game_state"]);
                    var gameObject = JsonConvert.DeserializeObject <GameObject>(form["game_state"]);
                    var bet        = PokerPlayer.BetRequest(json, gameObject).ToString();
                    var betBytes   = Encoding.UTF8.GetBytes(bet);
                    var response   = new Response {
                        ContentType = "text/plain",
                        Contents    = s => s.Write(betBytes, 0, betBytes.Length),
                        StatusCode  = HttpStatusCode.OK
                    };
                    return(response);
                }

                case "showdown":
                {
                    var json       = JObject.Parse(form ["game_state"]);
                    var gameObject = JsonConvert.DeserializeObject <GameObject>(form["game_state"]);
                    PokerPlayer.ShowDown(json, gameObject);
                    var showDownBytes = Encoding.UTF8.GetBytes("OK");
                    var response      = new Response {
                        ContentType = "text/plain",
                        Contents    = s => s.Write(showDownBytes, 0, showDownBytes.Length),
                        StatusCode  = HttpStatusCode.OK
                    };
                    return(response);
                }

                case "version":
                {
                    var versionBytes = Encoding.UTF8.GetBytes(PokerPlayer.VERSION);
                    return(new Response {
                            ContentType = "text/plain",
                            Contents = s => s.Write(versionBytes, 0, versionBytes.Length),
                            StatusCode = HttpStatusCode.OK
                        });
                }

                case "check":
                {
                    var contentBytes = Encoding.UTF8.GetBytes("OK");
                    var response     = new Response {
                        ContentType = "text/plain",
                        Contents    = s => s.Write(contentBytes, 0, contentBytes.Length),
                        StatusCode  = HttpStatusCode.OK
                    };
                    return(response);
                }

                default:
                    var bytes = Encoding.UTF8.GetBytes("Not an allowed action or request");
                    return(new Response {
                        ContentType = "text/plain",
                        Contents = s => s.Write(bytes, 0, bytes.Length),
                        StatusCode = HttpStatusCode.BadRequest
                    });
                }
            };
        }
コード例 #4
0
        private static void test()
        {
            var gs = JObject.Parse(@"{
""tournament_id"":""550d1d68cd7bd10003000003"",     // Id of the current tournament

    ""game_id"":""550da1cb2d909006e90004b1"",           // Id of the current sit'n'go game. You can use this to link a
                                                    // sequence of game states together for logging purposes, or to
                                                    // make sure that the same strategy is played for an entire game

    ""round"":0,                                      // Index of the current round within a sit'n'go

    ""bet_index"":0,                                  // Index of the betting opportunity within a round

    ""small_blind"": 10,                              // The small blind in the current round. The big blind is twice the
                                                    //     small blind

    ""current_buy_in"": 320,                          // The amount of the largest current bet from any one player

    ""pot"": 400,                                     // The size of the pot (sum of the player bets)

    ""minimum_raise"": 240,                           // Minimum raise amount. To raise you have to return at least:
                                                    //     current_buy_in - players[in_action][bet] + minimum_raise

    ""dealer"": 1,                                    // The index of the player on the dealer button in this round
                                                    //     The first player is (dealer+1)%(players.length)

    ""orbits"": 7,                                    // Number of orbits completed. (The number of times the dealer
                                                    //     button returned to the same player.)

    ""in_action"": 1,                                 // The index of your player, in the players array

    ""players"": [                                    // An array of the players. The order stays the same during the
        {                                           
            ""id"": 0,                               

            ""name"": ""Albert"",                     

            ""status"": ""active"",                    
            ""version"": ""Default random player"", 

            ""stack"": 1010,                        
                                                    

            ""bet"": 320                             
        },
        {
            ""id"": 1,                              
            ""name"": ""Bob"",
            ""status"": ""active"",
            ""version"": ""Default random player"",
            ""stack"": 1590,
            ""bet"": 80,
            ""hole_cards"": [                       
                                                    
                {
                    ""rank"": ""K"",                
                    ""suit"": ""hearts""            
                },
                {
                    ""rank"": ""K"",
                    ""suit"": ""spades""
                }
            ]
        },
        {
            ""id"": 2,
            ""name"": ""Chuck"",
            ""status"": ""out"",
            ""version"": ""Default random player"",
            ""stack"": 0,
            ""bet"": 0
        }
    ],
    ""community_cards"": [                            
        {
            ""rank"": ""4"",
            ""suit"": ""spades""
        },
        {
            ""rank"": ""A"",
            ""suit"": ""hearts""
        },
        {
            ""rank"": ""6"",
            ""suit"": ""clubs""
        }
    ]
}");

            Console.WriteLine(gs);
            PokerPlayer.BetRequest(gs);
        }
コード例 #5
0
        public MainModule()
        {
            Get ["/"] = _ => {
                var contentBytes = Encoding.UTF8.GetBytes("OK");
                var response     = new Response {
                    ContentType = "text/plain",
                    Contents    = s => s.Write(contentBytes, 0, contentBytes.Length),
                    StatusCode  = HttpStatusCode.OK
                };
                return(response);
            };

            Post ["/"] = parameters => {
                var    form   = Request.Form;
                string action = form ["action"];

                Guid reqId = PokerPlayer.GenerateRequestId();
                Logger.LogHelper.Log("type=incoming method=post action={0} request_id={1}", action, reqId);


                try
                {
                    switch (action)
                    {
                    case "bet_request":
                    {
                        var json     = JObject.Parse(form["game_state"]);
                        var bet      = PokerPlayer.BetRequest(json).ToString();
                        var betBytes = Encoding.UTF8.GetBytes(bet);
                        var response = new Response
                        {
                            ContentType = "text/plain",
                            Contents    = s => s.Write(betBytes, 0, betBytes.Length),
                            StatusCode  = HttpStatusCode.OK
                        };
                        return(response);
                    }

                    case "showdown":
                    {
                        var json = JObject.Parse(form["game_state"]);
                        PokerPlayer.ShowDown(json);
                        var showDownBytes = Encoding.UTF8.GetBytes("OK");
                        var response      = new Response
                        {
                            ContentType = "text/plain",
                            Contents    = s => s.Write(showDownBytes, 0, showDownBytes.Length),
                            StatusCode  = HttpStatusCode.OK
                        };
                        return(response);
                    }

                    case "version":
                    {
                        var versionBytes = Encoding.UTF8.GetBytes(PokerPlayer.VERSION);
                        return(new Response
                            {
                                ContentType = "text/plain",
                                Contents = s => s.Write(versionBytes, 0, versionBytes.Length),
                                StatusCode = HttpStatusCode.OK
                            });
                    }

                    case "check":
                    {
                        var contentBytes = Encoding.UTF8.GetBytes("OK");
                        var response     = new Response
                        {
                            ContentType = "text/plain",
                            Contents    = s => s.Write(contentBytes, 0, contentBytes.Length),
                            StatusCode  = HttpStatusCode.OK
                        };
                        return(response);
                    }

                    default:
                        var bytes = Encoding.UTF8.GetBytes("Not an allowed action or request");
                        return(new Response
                        {
                            ContentType = "text/plain",
                            Contents = s => s.Write(bytes, 0, bytes.Length),
                            StatusCode = HttpStatusCode.BadRequest
                        });
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogHelper.Log("type=incoming method=post action={0} request_id={1}, error: {2}", action, reqId, ex);

                    var betBytes = Encoding.UTF8.GetBytes("0");
                    var response = new Response
                    {
                        ContentType = "text/plain",
                        Contents    = s => s.Write(betBytes, 0, betBytes.Length),
                        StatusCode  = HttpStatusCode.OK
                    };
                    return(response);
                }
            };
        }
        public void WorstCardsEvah()
        {
            var state = PreflopAllin("2", Suit.Diamonds, "6", Suit.Clubs);

            Assert.That(PokerPlayer.BetRequest(state), Is.EqualTo(0));
        }
        public void PairOfAces()
        {
            var state = PreflopAllin("A", Suit.Diamonds, "A", Suit.Clubs);

            Assert.That(PokerPlayer.BetRequest(state), Is.EqualTo(1000));
        }