예제 #1
0
        public Action Act(ActionRequest request, GameState state)
        {
            if (state.CurrentPlayState == PlayState.PRE_FLOP)
            {
                //Check if possible
                if (request.Check != null)
                    return request.Check;

                //if we a suited card, call
                if (state.OwnCards.Any(c => c.Rank > Rank.TEN))
                    return request.Call;

                //The other players want play, but our hand is not looking that promising... fold
                return request.Fold;
            }

            var hand = evaluator.Evaluate(state.OwnCards.Concat(state.CommunityCards).ToArray());
            logger.Log(LogLevel.Info,String.Format("I hold a {0}",hand));
            // Let's go ALL IN if hand is better than or equal to THREE_OF_A_KIND
            if (request.AllIn != null && hand > PokerHand.TWO_PAIRS)
            {
                return request.AllIn;
            }

            // Otherwise, be more careful CHECK if possible.
            if (request.Check != null)
            {
                return request.Check;
            }

            // We have either CALL or RAISE left

            // Do I have something better than a pair and can RAISE?
            if (request.Raise != null && hand > PokerHand.ONE_PAIR)
            {
                return request.Raise;
            }

            // If we have a pair, then call
            if (request.Call != null && hand >= PokerHand.ONE_PAIR)
            {
                return request.Call;
            }

            //Arrrghhh.. I give up
            return request.Fold;
        }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                bot = new SimpleBot();
                Console.WriteLine("Cygni .net Client Version {0}", Assembly.GetExecutingAssembly().GetName().Version);
                Console.WriteLine("Bot:{0} {1}", bot.Name, bot.GetType().Name);
                Console.WriteLine("Hit Ctrl+C to quit\n\n");
                using (var socket = new TexasServerSocket(serverName, portNumber))
                {
                    var gameState = new GameState();

                    socket.Connect();
                    Console.WriteLine("Entering {0}, waiting for play to start...", roomName);
                    socket.Send(new RegisterForPlayRequest(bot.Name, roomName));
                    while (true)
                    {
                        foreach (var msg in socket.Receive())
                        {
                            if (msg is ActionRequest)
                            {
                                var request = msg as ActionRequest;
                                var action = bot.Act(request, gameState);
                                var response = new ActionResponse(action, request.RequestId);
                                logger.Log(LogLevel.Info,
                                    String.Format("Bot chose to {0} for {1}$", action.ActionType, action.Amount));
                                socket.Send(response);
                            }

                            else
                            {
                                gameState.UpdateFrom(msg);
                            }
                        }

                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("Ooops: " + ex);
                logger.LogException(LogLevel.Fatal, "Catastrophic error", ex);
            }
        }