Пример #1
0
        public static Situation evaluateSituation(Image tableImage, Table table, List <TableControl> controls, double bigblind)
        {
            // street
            StreetTypes street = getStreetType(table);

            // hand
            HandAnalysis analysis = HandEvaluator.evalHandSmart(table.Hand, table.Community);

            // opponents
            int opponents = (street == StreetTypes.Preflop ?
                             getPreflopNumberOfOpponents(table) :
                             getPostflopNumberOfOpponents(table));

            // action
            OpponentActionTypes action = (street == StreetTypes.Preflop ?
                                          getPreflopOpponentAction(tableImage, table, controls, bigblind) :
                                          getPostflopOpponentAction(tableImage, table, controls, bigblind));

            // position
            PositionTypes position = (street == StreetTypes.Preflop ?
                                      getPreflopPosition(table) :
                                      getPostflopPosition(table));

            return(new Situation(street, analysis.HandSmart, analysis.Chance, opponents, action, position));
        }
Пример #2
0
 public Situation(StreetTypes street, HandTypes hand,
                  ChanceTypes chance, int opponents,
                  OpponentActionTypes action, PositionTypes position)
 {
     this.street    = street;
     this.hand      = hand;
     this.chance    = chance;
     this.opponents = opponents;
     this.action    = action;
     this.position  = position;
 }
Пример #3
0
        public static List <Rule> readRules()
        {
            Log.Info("Reading spreadsheet '" + RULES_XLS + "'");
            Workbook    workbook  = Workbook.Load(RULES_XLS);
            Worksheet   worksheet = workbook.Worksheets[0];
            List <Rule> rules     = new List <Rule>();
            int         row       = 1;

            while (true)
            {
                // check
                if (isEmptyRow(worksheet, row))
                {
                    break;
                }
                Log.DebugIf(row % 100 == 0, "Reading row '" + (row + 1) + "'");

                // columns
                string hand     = worksheet.Cells[row, 2].StringValue;
                string street   = worksheet.Cells[row, 3].StringValue;
                string pot      = worksheet.Cells[row, 4].StringValue;
                string board    = worksheet.Cells[row, 5].StringValue;
                string opps     = worksheet.Cells[row, 6].StringValue;
                string action   = worksheet.Cells[row, 7].StringValue;
                string position = worksheet.Cells[row, 8].StringValue;
                string maxbet   = worksheet.Cells[row, 9].StringValue;
                string potsize  = worksheet.Cells[row, 10].StringValue;
                string decision = worksheet.Cells[row, 11].StringValue;

                // map
                StreetTypes         streetType   = mapStreetType(street);
                HandTypes           handType     = mapHandType(hand);
                ChanceTypes         chanceType   = mapChanceType(board);
                int                 minOpponents = mapMinOpponents(opps);
                int                 maxOpponents = mapMaxOpponents(opps);
                OpponentActionTypes actionType   = mapActionType(action);
                PositionTypes       positionType = mapPositionType(position);
                double              minMaxBet    = mapMinInterval(maxbet);
                double              maxMaxBet    = mapMaxInterval(maxbet);
                double              minPotSize   = mapMinInterval(potsize);
                double              maxPotSize   = mapMaxInterval(potsize);

                // rule
                Rule rule = new Rule(streetType, handType, chanceType, minOpponents,
                                     maxOpponents, actionType, positionType, minMaxBet, maxMaxBet,
                                     minPotSize, maxPotSize, decision);
                rules.Add(rule);

                // next
                row++;
            }
            Log.Info("Done reading spreadsheet");
            return(rules);
        }
Пример #4
0
 public Rule(StreetTypes street, HandTypes hand,
             ChanceTypes chance, int minOpps, int maxOpps,
             OpponentActionTypes action)
 {
     this.street   = street;
     this.hand     = hand;
     this.chance   = chance;
     this.minOpps  = minOpps;
     this.maxOpps  = maxOpps;
     this.action   = action;
     this.decision = NO_RULE;
 }
Пример #5
0
    public static SqlString GetStreet(SqlString address)
    {
        if (address.IsNull)
        {
            return(null);
        }
        if (string.IsNullOrWhiteSpace(address.Value))
        {
            return(null);
        }
        try
        {
            var s  = address.Value.Replace(".", "");
            var la = s.Split(' ').ToList();

            if (AllDigits(la[0]))
            {
                la.RemoveAt(0);
            }
            if (Quadrants.Contains(la[0].ToUpper()))
            {
                la.RemoveAt(0);
            }

            la.Reverse();
            if (AllDigits(la[0]))
            {
                la.RemoveAt(0);
            }
            if (la[0].StartsWith("#"))
            {
                la.RemoveAt(0);
            }
            if (Apartments.Contains(la[0].ToUpper()))
            {
                la.RemoveAt(0);
            }
            if (StreetTypes.Contains(la[0].ToUpper()))
            {
                la.RemoveAt(0);
            }
            la.Reverse();

            var street = string.Join(" ", la);
            return(street);
        }
        catch (Exception)
        {
            return(null);
        }
    }
Пример #6
0
        static MockPersonRepository()
        {
            var rng = new Random();

            // Ugly randomization to create different people
            people = Enumerable.Range(1, 30).Select(index => new Person
            {
                Id          = index,
                DateOfBirth = DateTime.Now.AddYears(-rng.Next(5, 40)),
                DateOfDeath = rng.Next(10) == 1 ? DateTime.Now.AddYears(-rng.Next(5)) : (DateTime?)null,
                FirstName   = FirstNames.GetRandom(),
                LastName    = LastNames.GetRandom(),
                Street1     = $"{rng.Next(999)} {Streets.GetRandom()} {StreetTypes.GetRandom()}",
                Street2     = rng.Next(10) < 3 ? $"Apt {rng.Next(1, 30)}" : null,
                City        = Cities.GetRandom(),
                State       = States.GetRandom(),
                PostalCode  = $"{rng.Next(99999):00000}",
                Interests   = rng.Next(10) < 5 ? Interests.GetRandom() : null,
                AvatarUrl   = $"/images/{(index % 2 == 0 ? "m" : "f")}/{index}.png"
            }).ToArray();
        }
Пример #7
0
 public Rule(StreetTypes street, HandTypes hand,
             ChanceTypes chance, int minOpps, int maxOpps,
             OpponentActionTypes action,
             PositionTypes position,
             double minMaxBet, double maxMaxBet,
             double minPotSize, double maxPotSize,
             string decision)
 {
     this.street     = street;
     this.hand       = hand;
     this.chance     = chance;
     this.minOpps    = minOpps;
     this.maxOpps    = maxOpps;
     this.action     = action;
     this.position   = position;
     this.minMaxBet  = minMaxBet;
     this.maxMaxBet  = maxMaxBet;
     this.minPotSize = minPotSize;
     this.maxPotSize = maxPotSize;
     this.decision   = decision;
 }
Пример #8
0
        public Rule findRule(StreetTypes street, HandTypes hand,
                             ChanceTypes chance, int opponents,
                             OpponentActionTypes action,
                             PositionTypes position,
                             double maxBet, double potSize)
        {
            // hash
            int hash = getHashCode(street, hand, chance, opponents, action, position);

            if (!rules.ContainsKey(hash))
            {
                Log.Debug("cannot find rule for this constellation -> "
                          + describe(street, hand, chance, opponents, action));
                return(new Rule(street, hand, chance, opponents, opponents, action));
            }

            // intervals
            MaxBetDictionary  maxBetDict  = rules[hash];
            PotSizeDictionary potSizeDict = maxBetDict.getByInterval(maxBet);
            Rule rule = potSizeDict.getByInterval(potSize);

            return(rule);
        }
Пример #9
0
        private int getHashCode(StreetTypes street, HandTypes hand,
                                ChanceTypes chance, int opponents,
                                OpponentActionTypes action,
                                PositionTypes position)
        {
            // ints
            int streetNum = (int)street;
            int handNum   = (int)hand;
            int chanceNum = (int)chance;
            int actionNum = (int)action;
            int posNum    = (int)position;

            // bits
            int bits = (streetNum & mask(4));

            bits |= (handNum & mask(6)) << 4;
            bits |= (chanceNum & mask(4)) << 10;
            bits |= (opponents & mask(4)) << 14;
            bits |= (actionNum & mask(4)) << 18;
            bits |= (posNum & mask(2)) << 22;

            // hash
            return(bits);
        }
Пример #10
0
        public static void Main(string[] args)
        {
            string              hand    = "2d 2s";
            string              board   = "9d 2h 7s 9s Ts";
            StreetTypes         street  = StreetTypes.River;
            int                 opps    = 1;
            OpponentActionTypes action  = OpponentActionTypes.Raise;
            double              maxBet  = 1.26;
            double              potSize = 0.64;

            HandAnalysis analysis = HandEvaluator.evalHandSmart(CardParser.parse(hand), CardParser.parse(board));

            Console.WriteLine("chance = " + analysis.Chance);
            Console.WriteLine("basic = " + analysis.HandBasic);
            Console.WriteLine("smart = " + analysis.HandSmart);

            List <Rule>   rules = RulesReader.readRules();
            RuleEvaluator eval  = new RuleEvaluator(rules);
            Rule          rule  = eval.findRule(street, analysis.HandSmart, analysis.Chance, opps, action, PositionTypes.Early, maxBet, potSize);

            Console.WriteLine("rule = " + rule.Decision);

            Console.ReadKey();
        }
Пример #11
0
    // Update is called once per frame
    void Update()
    {
        // tiles is array of possible tiles to place
        if (tiles.Length == 0)
        {
            return;
        }

        // We're not editing right now
        if (stateManager.GetComponent <StateManager> ().getState() != StateManager.GameStates.Editing)
        {
            return;
        }

        // Make sure the mouse isn't on the UI
        if (!onUI)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Transform objectHit = hit.transform;

                if (objectHit.gameObject.tag != "Floor")
                {
                    return;
                }

                int xVal, yVal;

                if (!lastFloor)
                {
                    lastFloor = objectHit.gameObject;
                    xVal      = lastFloor.GetComponent <GridTile> ().xVal;
                    yVal      = lastFloor.GetComponent <GridTile> ().yVal;
                }

                if (buildState == State.Deleting)
                {
                    GameObject currentFloor = objectHit.gameObject;

                    // if clicked and they have a floor highlighted we need to delete
                    if (Input.GetMouseButtonDown(0))
                    {
                        if (currentFloor && currentFloor.GetComponent <GridTile> ().blocked)
                        {
                            removeTile(currentFloor.GetComponent <GridTile> ().xVal, currentFloor.GetComponent <GridTile> ().yVal);

                            foreach (GameObject obj in coloredErasingObjects)
                            {
                                if (obj)
                                {
                                    iTween.ColorUpdate(obj, Color.white, 0.01f);
                                }
                            }
                            coloredErasingObjects.Clear();
                        }
                    }
                    else if (!currentFloor.Equals(lastFloor))
                    {
                        if (coloredErasingObjects.Count > 0)
                        {
                            foreach (GameObject obj in coloredErasingObjects)
                            {
                                if (obj)
                                {
                                    iTween.ColorUpdate(obj, Color.white, 0.01f);
                                }
                            }
                            coloredErasingObjects.Clear();
                        }
                        lastFloor = currentFloor;
                    }
                    else
                    {
                        if (currentFloor.GetComponent <GridTile> ().blocked)
                        {
                            coloredErasingObjects.Clear();
                            coloredErasingObjects.Add(currentFloor.GetComponent <GridTile> ().tileObject);
                            coloredErasingObjects.Add(currentFloor);

                            foreach (GameObject obj in coloredErasingObjects)
                            {
                                if (obj)
                                {
                                    iTween.ColorUpdate(obj, Color.red, 2.5f);
                                }
                            }
                        }
                    }
                }
                else if (buildState == State.Placing)
                {
                    if (Input.GetMouseButtonDown(0) && lastFloor)
                    {
                        xVal = lastFloor.GetComponent <GridTile> ().xVal;
                        yVal = lastFloor.GetComponent <GridTile> ().yVal;

                        justPlacedItem = placeTile(xVal, yVal);

                        if (justPlacedItem && tileIndex != Type.Street)
                        {
                            if (tileIndex != Type.Train && tileIndex != Type.Airport && numberOfConnectedTilesForTileType(xVal, yVal, tileIndex) < 1)
                            {
                                forcedTileIndex   = tileIndex;
                                currentForcedTile = lastFloor;
                                buildState        = State.ForcePlacing;

                                if (gameButtonManager)
                                {
                                    gameButtonManager.GetComponent <GameButtonManager> ().forceButton(0);
                                }
                                Debug.Log("BuildState now at ForcePlacing");
                            }
                            else if (gameButtonManager)
                            {
                                gameButtonManager.GetComponent <GameButtonManager> ().selectButton(0, false);
                            }

                            tileIndex = Type.Street;
                        }
                        else
                        {
                            // Tile is blocked
                            if (lastFloor.GetComponent <GridTile> ().blocked)
                            {
                                StreetTypes streetType = (StreetTypes)lastFloor.GetComponent <GridTile> ().streetType;

                                if (streetType == StreetTypes.Intersection || streetType == StreetTypes.TIntersection)
                                {
                                    // BRING UP STOPLIGHT GUI

                                    trafficLightUI.SetActive(true);
                                    trafficLightUI.GetComponent <TrafficLightUI>().setTrafficTile(lastFloor);
                                    stateManager.GetComponent <StateManager>().setState(StateManager.GameStates.Paused);

                                    GameObject intersection = lastFloor.GetComponent <GridTile> ().tileObject;
                                }
                            }
                        }
                    }
                    else if (!objectHit.gameObject.Equals(lastFloor))
                    {
                        lastFloor = objectHit.gameObject;

                        destroyGhost();

                        if (!(lastFloor.GetComponent <GridTile> ().blocked&& justPlacedItem))
                        {
                            xVal = lastFloor.GetComponent <GridTile> ().xVal;
                            yVal = lastFloor.GetComponent <GridTile> ().yVal;

                            createGhost(xVal, yVal);
                            justPlacedItem = false;
                        }
                    }
                    else if (!isTileFreeAtPos(lastFloor.GetComponent <GridTile> ().xVal, lastFloor.GetComponent <GridTile> ().yVal))
                    {
                        xVal = lastFloor.GetComponent <GridTile> ().xVal;
                        yVal = lastFloor.GetComponent <GridTile> ().yVal;

                        if (!justPlacedItem)
                        {
                            colorTiles(xVal, yVal, Color.red);
                        }
                    }
                    else
                    {
                        xVal = lastFloor.GetComponent <GridTile> ().xVal;
                        yVal = lastFloor.GetComponent <GridTile> ().yVal;

                        colorTiles(xVal, yVal, Color.green);
                        if (justPlacedItem)
                        {
                            justPlacedItem = false;
                        }
                    }

                    xVal = lastFloor.GetComponent <GridTile> ().xVal;
                    yVal = lastFloor.GetComponent <GridTile> ().yVal;

                    if (!currentGhost && !objectHit.gameObject.GetComponent <GridTile>().blocked&& !isErasingTiles)
                    {
                        createGhost(xVal, yVal);
                    }
                }
                else if (buildState == State.ForcePlacing)
                {
                    if (!currentForcedTile)
                    {
                        buildState = State.Placing;
                        Debug.Log("No currentForcedTile, BuildState now at Placing");
                        return;
                    }

                    if (Input.GetMouseButtonDown(0) && currentForcedGhostTile)
                    {
                        justPlacedItem = placeTile(currentForcedGhostTile.GetComponent <GridTile> ().xVal, currentForcedGhostTile.GetComponent <GridTile> ().yVal);

                        if (justPlacedItem)
                        {
                            buildState = State.Placing;
                            Debug.Log("ForcePlace successful, BuildState now at Placing");
                            gameButtonManager.GetComponent <GameButtonManager> ().releaseButton();
                        }
                    }
                    else if (!objectHit.gameObject.Equals(lastFloor) || !currentGhost)
                    {
                        lastFloor = objectHit.gameObject;

                        xVal = lastFloor.GetComponent <GridTile> ().xVal;
                        yVal = lastFloor.GetComponent <GridTile> ().yVal;

                        int xValForced = -1, yValForced = -1;

                        if (currentForcedGhostTile)
                        {
                            xValForced = currentForcedGhostTile.GetComponent <GridTile> ().xVal;
                            yValForced = currentForcedGhostTile.GetComponent <GridTile> ().yVal;
                        }

                        Vector2 xyVal = closestForcedTileToPos(xVal, yVal);

                        if (!currentForcedGhostTile || !Vector2.Equals(xyVal, new Vector2(xValForced, yValForced)))
                        {
                            destroyGhost();

                            createGhost((int)xyVal.x, (int)xyVal.y);
                            currentForcedGhostTile = placedTiles[(int)xyVal.x, (int)xyVal.y];
                        }
                    }
                    else if (!isTileFreeAtPos(currentForcedGhostTile.GetComponent <GridTile> ().xVal, currentForcedGhostTile.GetComponent <GridTile> ().yVal))
                    {
                        xVal = currentForcedGhostTile.GetComponent <GridTile> ().xVal;
                        yVal = currentForcedGhostTile.GetComponent <GridTile> ().yVal;

                        if (!justPlacedItem)
                        {
                            colorTiles(xVal, yVal, Color.red);
                        }
                    }
                    else
                    {
                        xVal = currentForcedGhostTile.GetComponent <GridTile> ().xVal;
                        yVal = currentForcedGhostTile.GetComponent <GridTile> ().yVal;

                        colorTiles(xVal, yVal, Color.green);
                        if (justPlacedItem)
                        {
                            justPlacedItem = false;
                        }
                    }
                }
            }
        }
    }
Пример #12
0
        public Address GetAddress(string smsBody)
        {
            Address address = null;
            int     x;

            string[] splitString = smsBody.Split(new char[] { ' ', ',', '!', '(', ')', '?', '#', '&', '.', '-' },
                                                 StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < splitString.Length; i++)
            {
                splitString[i] = splitString[i].Trim(',', '!', '?', '.', '-', '(', ')', '#');
            }


            //search for number
            for (int i = 0; i < splitString.Length; i++)
            {
                bool foundNumber = int.TryParse(splitString[i], out x);
                if (!foundNumber)
                {
                    continue;
                }

                // If number is found and string is not last in array
                if (i + 1 < splitString.Length)
                {
                    // If Street Direction is found
                    if (
                        StreetDirections.Any(
                            d => String.Equals(d, splitString[i + 1], StringComparison.OrdinalIgnoreCase)) &&
                        i + 1 < splitString.Length)
                    {
                        //i = HouseNumber
                        //[i+1] = Direction
                        //[i+2] = StreetNameWithoutSpace
                        //[i+3] ?= StreetType

                        // If Street Name w/o space is found
                        if (
                            i + 2 < splitString.Length &&
                            ValidStreetNamesWithOutSpace.Any(
                                n => String.Equals(n, splitString[i + 2], StringComparison.OrdinalIgnoreCase)))
                        {
                            address = new Address()
                            {
                                HouseNumber     = x,
                                StreetDirection = splitString[i + 1],
                                StreetName      = splitString[i + 2]
                            };
                            if (i + 3 < splitString.Length &&
                                StreetTypes.Any(
                                    t => String.Equals(t, splitString[i + 3], StringComparison.OrdinalIgnoreCase)))
                            {
                                address.StreetType = splitString[i + 3];
                            }
                            break;
                        }
                        //If Street Name with space is found
                        else if (
                            //i = HouseNumber
                            //[i+1] = Direction
                            //[i+2] = StreetName1
                            //[i+3] = StreetName2
                            //[i+4] ?= StreetType
                            i + 3 < splitString.Length &&
                            StreetNamesWithSpace.Any(
                                n =>
                                String.Equals(n,
                                              String.Format(splitString[i + 2] + " " + splitString[i + 3],
                                                            StringComparison.OrdinalIgnoreCase))))
                        {
                            address = new Address()
                            {
                                HouseNumber     = x,
                                StreetDirection = splitString[i + 1],
                                StreetName      = splitString[i + 2] + " " + splitString[i + 3]
                            };
                            if (i + 4 < splitString.Length &&
                                StreetTypes.Any(
                                    t => String.Equals(t, splitString[i + 4], StringComparison.OrdinalIgnoreCase)))
                            {
                                address.StreetType = splitString[i + 4];
                            }
                            break;
                        }
                    }
                    // If no Street Direction is found
                    else if (
                        //i = HouseNumber
                        //[i+1] = StreetName1
                        //[i+2] ?= StreetType
                        i + 1 < splitString.Length &&
                        ValidStreetNamesWithOutSpace.Any(
                            n => String.Equals(n, splitString[i + 1], StringComparison.OrdinalIgnoreCase)))
                    {
                        address = new Address()
                        {
                            HouseNumber = x,
                            StreetName  = splitString[i + 1],
                        };
                        if (i + 2 < splitString.Length &&
                            StreetTypes.Any(
                                t => String.Equals(t, splitString[i + 2], StringComparison.OrdinalIgnoreCase)))
                        {
                            address.StreetType = splitString[i + 2];
                        }
                        break;
                    }
                    else if (
                        //i = HouseNumber
                        //[i+1] = StreetName1
                        //[i+2] = StreetName2
                        //[i+3] ?= StreetType
                        i + 2 < splitString.Length &&
                        StreetNamesWithSpace.Any(
                            n => String.Equals(n, String.Format(splitString[i + 1] + " " + splitString[i + 2]))))

                    {
                        address = new Address()
                        {
                            HouseNumber = x,
                            StreetName  = splitString[i + 1] + " " + splitString[i + 2],
                        };
                        if (i + 3 < splitString.Length &&
                            StreetTypes.Any(
                                t => String.Equals(t, splitString[i + 3], StringComparison.OrdinalIgnoreCase)))
                        {
                            address.StreetType = splitString[i + 3];
                        }
                        break;
                    }
                }
            }

            return(address);
        }
Пример #13
0
 private string describe(StreetTypes street, HandTypes hand,
                         ChanceTypes chance, int opponents,
                         OpponentActionTypes action)
 {
     return(hand + " " + street + " " + chance + " " + opponents + " " + action);
 }