public FlopRoot(Node Parent, CommunityNode Community, int Spent, int Pot, int RootCount)
     : base(Parent, Community, Spent, Pot, RootCount)
 {
     #if DEBUG
     InstanceCount++;
     #endif
 }
        public Junction(Node parent, CommunityNode Community, int Spent, int Pot)
            : base(parent, Spent, Pot)
        {
            Weight = 0;

            this.Spent = Spent;
            this.Pot = Pot;
            Assert.That(Spent == Pot);

            MyCommunity = Community;
            Phase = MyCommunity.Phase;

            Initialize();
        }
        public ShowdownNode(Node parent, int Pot)
            : base(parent, Pot, Pot)
        {
            //RiverRoot LastPhase = MyPhaseRoot as RiverRoot;
            //PocketValue = LastPhase.PocketValue;

            PocketValue = ((RiverCommunity)MyCommunity).PocketValue;

            Initialize();

            #if DEBUG
            InstanceCount++;
            #endif
        }
        public PhaseRoot(Node Parent, CommunityNode Community, int Spent, int Pot, int RootCount)
            : base(Parent, Spent, Pot)
        {
            MyPhaseRoot = this;
            MyCommunity = Community;

            Weight = MyCommunity.Weight;
            Phase = MyCommunity.Phase;
            InitiallyActivePlayer = MyCommunity.InitiallyActivePlayer;

            DataOffset = MaxDepth + RootCount;
            if (Phase == BettingPhase.Turn) DataOffset += Flop.N;
            if (Phase == BettingPhase.River) DataOffset += Flop.N + Card.N;

            Initialize();
        }
        public BetNode(Node parent, PlayerAction ActionTaken, Player ActivePlayer, int Spent, int Pot, int NumRaises, int DataOffset = 0)
            : base(parent, Spent, Pot)
        {
            switch (ActionTaken)
            {
                case PlayerAction.Raise:	BetCode += 'r'; break;
                case PlayerAction.Call:		BetCode += 'c'; break;

                case PlayerAction.Fold:		Assert.NotReached(); break;
                default:					BetCode += '/'; break;
            }

            Phase = MyPhaseRoot.Phase;
            Weight = 0;

            this.ActivePlayer = ActivePlayer;
            this.NumRaises = NumRaises;

            this.DataOffset += DataOffset;

            #if DEBUG
            InstanceCount++;
            #endif
        }
 public CallFoldNode(Node parent, PlayerAction ActionTaken, Player ActivePlayer, int Spent, int Pot, int NumRaises, int DataOffset = 0)
     : base(parent, ActionTaken, ActivePlayer, Spent, Pot, NumRaises, DataOffset)
 {
     Initialize();
 }
        public override void SetTurn(int c1)
        {
            if (DerivedSetup.SuitReduce)
            {
                TrueTurn = c1;
                c1 = TrueFlop.CardMap[c1];
            }

            Head = Head.AdvanceHead(c1);
        }
 public SimultaneousNode(Node parent, int Spent, int Pot, BettingPhase Phase)
     : base(parent, Spent, Pot)
 {
     this.Phase = Phase;
     Initialize();
 }
        protected override void CreateBranches()
        {
            if (Phase == BettingPhase.River)
                CallBranch = new ShowdownNode(this, Pot);
            else
                CallBranch = Junction.GetJunction(Phase, this, Pot, Pot);

            Branches = new List<Node>(1);
            Branches.Add(CallBranch);
        }
        protected override void CreateBranches()
        {
            if (BetNode.SimultaneousBetting)
                BettingBranch = new SimultaneousNode(this, Spent, Pot, Phase);
            else
            {
                if (Phase == BettingPhase.PreFlop)
                    BettingBranch = new FirstActionNode_PreFlop(this, InitiallyActivePlayer, Spent, Pot);
                else
                    BettingBranch = new FirstActionNode_PostFlop(this, InitiallyActivePlayer, Spent, Pot);
            }

            Branches = new List<Node>(1);
            Branches.Add(BettingBranch);
        }
        protected override void CreateBranches()
        {
            int NewPot = Pot;
            switch (Phase)
            {
                case BettingPhase.PreFlop: NewPot += Setup.PreFlop; break;
                case BettingPhase.Flop: NewPot += Setup.Flop; break;
                case BettingPhase.Turn: NewPot += Setup.Turn; break;
                case BettingPhase.River: NewPot += Setup.River; break;
            }

            if (Phase == BettingPhase.River)
                RaiseBranch = new ShowdownNode(this, NewPot);
            else
                RaiseBranch = Junction.GetJunction(Phase, this, NewPot, NewPot);

            Branches = new List<Node>(1);
            Branches.Add(RaiseBranch);
        }
        public PlayerAction GetAction_Simultaneous()
        {
            PocketData Data = Strategy(Head);

            number d = MyGame.Rand();
            PlayerAction action = PlayerAction.Nothing;
            if (d < Data[Pocket])
                action = PlayerAction.Raise;
            else
                action = PlayerAction.Fold;

            Head = Head.AdvanceHead(action);
            return action;
        }
 //public static Node GetJunction(BettingPhase Phase, Node parent, int Spent, int Pot)
 //{
 //    return new PocketShowdownNode(parent, Pot);
 //}
 public static Junction GetJunction(BettingPhase Phase, Node Parent, int Spent, int Pot)
 {
     return new Junction(Parent, Parent.MyCommunity, Spent, Pot);
 }
 public FirstActionNode_PreFlop(Node parent, Player ActivePlayer, int Spent, int Pot)
     : base(parent, PlayerAction.Nothing, ActivePlayer, Spent, Pot, 0)
 {
 }
        protected override void CreateBranches()
        {
            if (NumRaises + 1 == AllowedRaises)
                RaiseBranch =      new CallFoldNode(this, PlayerAction.Raise, Tools.NextPlayer(ActivePlayer), Pot, Pot + RaiseVal, NumRaises + 1, Node.MaxDepth / 2);
            else
                RaiseBranch = new RaiseCallFoldNode(this, PlayerAction.Raise,  Tools.NextPlayer(ActivePlayer), Pot, Pot + RaiseVal, NumRaises + 1, Node.MaxDepth / 2);

            if (Phase == BettingPhase.River)
                CallBranch = new ShowdownNode(this, Pot);
            else
                CallBranch = Junction.GetJunction(Phase, this, Pot, Pot);

            Branches = new List<Node>(2);
            Branches.Add(RaiseBranch);
            Branches.Add(CallBranch);
        }
 public override void SetPocket(int c1, int c2)
 {
     Pocket = Game.PocketLookup[c1, c2];
     Head = Head.AdvanceHead(PlayerAction.Nothing);
 }
        public override void SetFlop(int c1, int c2, int c3)
        {
            int flop = Game.FlopLookup[c1, c2, c3];

            if (DerivedSetup.SuitReduce)
            {
                TrueFlop = Flop.Flops[flop];
                flop = Flop.RepresentativeOf(flop);

                TruePocket = Pocket;
                Pocket = TrueFlop.PocketMap[Pocket];
            }

            Head = Head.AdvanceHead(flop);
        }
 public override void Reset()
 {
     Head = PocketRoot.Root;
 }
 public override void OpponentDoes(PlayerAction action)
 {
     if (BetNode.SimultaneousBetting)
         return;
     else
         Head = Head.AdvanceHead(action);
 }
        /* This code is for dynamically generating file strings at save/load time instead of always keeping the file names in memory.
        protected string FileString()
        {
            var ParentString = Parent.FileString();
            var MyAddtionalString = FileStringBit();

            if (ParentString != null)
            {
                if (MyAddtionalString != null)
                    return ParentString + MyAddtionalString;
                else
                    return ParentString;
            }
            else
            {
                if (MyAddtionalString != null)
                    return MyAddtionalString;
                else
                    return null;
            }
        }

        protected virtual string FileStringBit()
        {
            return null;
        }
         * */
        public Node(Node parent, int Spent, int Pot)
        {
            Parent = parent;

            if (Parent == null)
                BetCode = null;
            else
                BetCode = Parent.BetCode;

            if (Parent != null)
            {
                MyPhaseRoot = Parent.MyPhaseRoot;
                MyCommunity = Parent.MyCommunity;
                Depth = Parent.Depth + 1;
            }
            else
            {
                MyPhaseRoot = null;
                MyCommunity = null;
                Depth = 0;
            }

            DataOffset = Depth;

            this.Spent = Spent;
            this.Pot = Pot;
        }
        public PlayerAction GetAction_Complex()
        {
            PocketData Data = Strategy(Head);

            number d = MyGame.Rand();

            PlayerAction action = PlayerAction.Nothing;

            RaiseCallFoldData RCF = Data as RaiseCallFoldData;
            if (null != RCF)
            {
                if (d < RCF.Raise[Pocket])
                    action = PlayerAction.Raise;
                else if (d < RCF.Raise[Pocket] + RCF.Call[Pocket])
                    action = PlayerAction.Call;
                else
                    action = PlayerAction.Fold;
            }
            else if (Head is RaiseCheckNode)
            {
                if (d < Data[Pocket])
                    action = PlayerAction.Raise;
                else
                    action = PlayerAction.Call;
            }
            else
            {
                if (d < Data[Pocket])
                    action = PlayerAction.Call;
                else
                    action = PlayerAction.Fold;
            }

            Head = Head.AdvanceHead(action);
            return action;
        }
 public RaiseCheckNode(Node parent, PlayerAction ActionTaken, Player ActivePlayer, int Spent, int Pot, int NumRaises)
     : base(parent, ActionTaken, ActivePlayer, Spent, Pot, NumRaises)
 {
     Assert.That(Spent == Pot);
     Initialize();
 }