Score() public method

public Score ( int player ) : int
player int The player who's current match score is returned.
return int
コード例 #1
0
ファイル: GnuBG.cs プロジェクト: alexhanh/Botting-Library
 /// <summary>
 /// TODO: Solve the "I'm sorry, but SetMatchID cannot handle positions where a double has been offered" bullshit.
 /// </summary>
 /// <param name="gamestate"></param>
 /// <returns></returns>
 public static string MatchID(GameState gamestate)
 {
     Console.WriteLine("Cube owner: " + gamestate.Cube.Owner);
     return MatchID(
         gamestate.Dice[0],
         gamestate.Dice[1],
         gamestate.PlayerOnTurn,
         (int)gamestate.ResignOfferValue,
         (gamestate.OfferType == OfferType.Double) ? 1 : 0,
         gamestate.PlayerOnRoll,
         (gamestate.Cube.Owner >= 0) ? gamestate.Cube.Owner : 2,
         gamestate.IsCrawford ? 1 : 0,
         gamestate.MatchTo,
         gamestate.Score(0),
         gamestate.Score(1),
         gamestate.Cube.Value,
         (int)GnuBGGameState.GAME_PLAYING
         );
 }
コード例 #2
0
ファイル: GnuBG.cs プロジェクト: alexhanh/Botting-Library
        /// <summary>
        /// Doesn't use the match id for setting up the position.
        /// </summary>
        /// <param name="gamestate"></param>
        public void SetGameState(GameState gamestate)
        {
            bool set_cube = true;
            if (gamestate.GameType == GameType.Money)
            {
                int wager = gamestate.Stake * gamestate.Cube.Value;
                bool capped = (wager >= gamestate.Limit);
                // Evaluate as a single point match if the game is capped or the cube is centered (jacoby rule) and leave the cube at the center.
                if (gamestate.DiceRolled && (capped || gamestate.Cube.Centered))
                {
            //					Console.WriteLine("EVALUATING AS A MATCH");
                    Command("new match 1");
                    set_cube = false;
                }
                else
                {
                    int max_points = (int)(gamestate.Limit / gamestate.Stake);

                    if (max_points * gamestate.Stake < gamestate.Limit)
                        max_points++;

                    if (max_points < 1)
                        max_points = 1;

                    if (gamestate.Stake < gamestate.Limit && (met_stake != gamestate.Stake || met_limit != gamestate.Limit))
                    {
            //						Console.WriteLine("Setting money MET.");
                        MatchEquityTable.CreateRakelessMet("gnubg/met.xml", gamestate.Stake, gamestate.Limit);

                        Command("set met met.xml");

                        met_stake = gamestate.Stake;
                        met_limit = gamestate.Limit;
                    }

                    Command("new match " + max_points);
                }
            }
            else if (gamestate.GameType == GameType.Match) // What is only set in matches.
            {
                Command("new match " + gamestate.MatchTo);

                Command("set score " + gamestate.Score(0) + " " + gamestate.Score(1));
                // The score (after 0 games) is: gnubg 2, Administrator 2 (match to 3 points, post-Crawford play).

                // Need to be 1-away from match length to be able to set crawford game.
                if (gamestate.MatchTo - gamestate.Score(0) == 1 ||
                    gamestate.MatchTo - gamestate.Score(1) == 1)
                    Command("set crawford " + (gamestate.IsCrawford ? "true" : "false"));
                // Cannot set Crawford play for money sessions.
                // This game is the Crawford game (no doubling allowed).
            }
            else
            {
            }

            // This also clears the dice!
            Command("set turn " + gamestate.PlayerOnRoll);

            SetBoardSimple(gamestate);

            if (gamestate.OfferType == OfferType.Double)
            {
                Command("set turn " + gamestate.Cube.Owner);
                Command("set cube owner " + gamestate.Cube.Owner);// gamestate.PlayerOnRoll);
                Command("set cube value " + (gamestate.Cube.Value / 2));

                Command("double");
            }
            else if (gamestate.OfferType == OfferType.Resign)
            {
                if (gamestate.ResignOfferValue == ResignValue.None)
                    Console.WriteLine("Resign offer but ResignValue == None!");

                Command("resign " + (int)gamestate.ResignOfferValue);
            }
            else
            {
                if (gamestate.DiceRolled)
                    Command("set dice " + gamestate.Dice[0] + " " + gamestate.Dice[1]);
                // The dice have been set to 6 and 6.

                if (gamestate.Cube.Centered || !set_cube)
                {
                    Command("set cube center");
                    // The cube has been centred.
                }
                else
                {
                    Command("set cube owner " + gamestate.Cube.Owner);
                    // gnubg now owns the cube.

                    Command("set cube value " + gamestate.Cube.Value);
                    // The cube has been set to 2.
                }
            }
        }
コード例 #3
0
        // See drawboard.c in Gnubg source files.
        public static string ToGnuBgASCII(GameState gs, string[] player_names)
        {
            string[] a = new string[7];

            string achX = "     X6789ABCDEF";
            string achO = "     O6789ABCDEF";

            a[0] = string.Format("O: {0}", player_names[0]);
            a[6] = string.Format("X: {0}", player_names[1]);

            if (gs.Score(0) == 1)
                a[1] = string.Format("{0} point", gs.Score(0));
            else
                a[1] = string.Format("{0} points", gs.Score(0));

            if (gs.Score(1) == 1)
                a[5] = string.Format("{0} point", gs.Score(1));
            else
                a[5] = string.Format("{0} points", gs.Score(1));

            if (gs.OfferType == OfferType.Double)
            {
                a[(gs.PlayerOnTurn == 1) ? 4 : 2] = string.Format("Cube offered at {0}", gs.Cube.Value);
            }
            else
            {
                int index = (gs.PlayerOnRoll == 1) ? 4 : 2;

                if (gs.DiceRolled)
                    a[index] += string.Format("Rolled {0}{1}", gs.Dice[0], gs.Dice[1]);
                else if (!gs.HasOffer)
                    a[index] = "On roll";
                else
                {
                }

                if (gs.Cube.Centered)
                {
                    if (gs.GameType == GameType.Match)
                        a[3] += string.Format("{0} point match (Cube: {1})", gs.MatchTo, gs.Cube.Value);
                    else
                        a[3] += string.Format("(Cube: {0})", gs.Cube.Value);
                }
                else
                {
                    a[(gs.Cube.Owner == 1) ? 6 : 0] = string.Format("{0}: {1} (Cube: {2})", (gs.Cube.Owner == 1) ? "X" : "O", "CubeOwnersName", gs.Cube.Value);

                    if (gs.GameType == GameType.Match)
                        a[3] += string.Format("{0} point match", gs.MatchTo);
                }
            }

            if (gs.OfferType == OfferType.Resign)
            {
                string[] resign_strigns = new string[] { "single game", "gammon", "backgammon" };
                a[(gs.PlayerOnRoll == 1) ? 4 : 2] += string.Format(", resigns {0}", resign_strigns[(int)gs.ResignOfferValue - 1]);
            }

            Board b = gs.Board;
            Console.WriteLine(b.CapturedCount(0) + " " + b.CapturedCount(1));
            if (gs.PlayerOnRoll == 0)
                b = SwapSides(b);

            string s = "";

            s += string.Format(" {0,-15} {1}: ", "GNU Backgammon", "Position ID");

            s += "4HPwATDg6+ABMA";//GnuBg.ToPositionID(gs.Board, gs.PlayerOnRoll);

            s += Environment.NewLine;

            s += string.Format("                 {0}   : {1}" + Environment.NewLine, "Match ID", "MQHgAAAACAAA"); //GnuBg.ToMatchID(gs);

            s += (gs.PlayerOnRoll == 1) ? " +13-14-15-16-17-18------19-20-21-22-23-24-+     " : " +12-11-10--9--8--7-------6--5--4--3--2--1-+     ";

            s += a[0] + Environment.NewLine;
            Console.WriteLine(b.CapturedCount(0) + " " + b.CapturedCount(1));
            int x = 0, y = 0;
            for (y = 0; y < 4; y++)
            {
                s += " ";
                s += "|";

                for (x = 12; x < 18; x++)
                {
                    s += " ";
                    s += (b.PointCount(1, x) > y) ? "X" : (b.PointCount(0, 23 - x) > y) ? "O" : " "; // X or O or ' ' TODO!
                    s += " ";
                }

                s += "|";
                s += " ";
                s += b.CapturedCount(0) > y ? "O" : " "; // O or ' ' TODO!
                s += " ";
                s += "|";

                for (; x < 24; x++)
                {
                    s += " ";
                    s += (b.PointCount(1, x) > y) ? "X" : (b.PointCount(0, 23 - x) > y) ? "O" : " "; // X or O or ' ' TODO!
                    s += " ";
                }

                s += "|";
                s += " ";

                for (x = 0; x < 3; x++)
                    s += b.FinishedCount(0) > (5 * x + y) ? "O" : " "; // O or ' ' TODO!

                s += " ";

                if (y < 2 && a[y + 1] != "")
                {
                    s += a[y + 1];
                }

                s += Environment.NewLine;
            }

            s += " ";
            s += "|";

            for (x = 12; x < 18; x++)
            {
                s += " ";
                s += b.PointCount(1, x) > 0 ? achX[b.PointCount(1, x)] : achO[b.PointCount(0, 23 - x)];// TODO, WTF?
                s += " ";
            }

            s += "|";
            s += " ";
            s += achO[b.CapturedCount(0)]; // TODO!
            s += " ";
            s += "|";

            for (; x < 24; x++)
            {
                s += " ";
                s += b.PointCount(1, x) > 0 ? achX[b.PointCount(1, x)] : achO[b.PointCount(0, 23 - x)]; // TODO!
                s += " ";
            }

            s += "|";
            s += " ";

            for (x = 0; x < 3; x++)
                s += b.FinishedCount(0) > (5 * x + 4) ? "O" : " "; ; // TODO!

            s += Environment.NewLine;

            s += (gs.PlayerOnRoll == 1) ? "v" : "^";

            s += "|                  |BAR|                  |     ";

            s += a[3];

            s += Environment.NewLine;

            s += " ";
            s += "|";

            for (x = 11; x > 5; x--)
            {
                s += " ";
                s += b.PointCount(1, x) > 0 ? achX[b.PointCount(1, x)] : achO[b.PointCount(0, 23 - x)]; // TODO!
                s += " ";
            }

            s += "|";
            s += " ";
            s += achX[b.CapturedCount(1)]; // TODO!
            s += " ";
            s += "|";

            for (; x >= 0; x--)
            {
                s += " ";
                s += b.PointCount(1, x) > 0 ? achX[b.PointCount(1, x)] : achO[b.PointCount(0, 23 - x)]; // TODO!
                s += " ";
            }

            s += "|";
            s += " ";

            for (x = 0; x < 3; x++)
                s += b.FinishedCount(1) > (5 * x + 4) ? "X" : " "; // TODO!

            s += Environment.NewLine;

            for (y = 3; y >= 0; y--)
            {
                s += " ";
                s += "|";

                for (x = 11; x > 5; x--)
                {
                    s += " ";
                    s += b.PointCount(1, x) > y ? "X" : b.PointCount(0, 23 - x) > y ? "O" : " "; // TODO!
                    s += " ";
                }

                s += "|";
                s += " ";
                s += b.CapturedCount(1) > y ? "X" : " "; // TODO!
                s += " ";
                s += "|";

                for (; x >= 0; x--)
                {
                    s += " ";
                    s += b.PointCount(1, x) > y ? "X" : b.PointCount(0, 23 - x) > y ? "O" : " "; // TODO!
                    s += " ";
                }

                s += "|";
                s += " ";

                for (x = 0; x < 3; x++)
                    s += b.FinishedCount(1) > (5 * x + y) ? "X" : " "; // TODO!

                s += " ";

                if (y < 2)
                    s += a[5 - y];

                s += Environment.NewLine;
            }

            s += (gs.PlayerOnRoll == 1) ? " +12-11-10--9--8--7-------6--5--4--3--2--1-+     " : " +13-14-15-16-17-18------19-20-21-22-23-24-+     ";

            s += a[6];

            s += Environment.NewLine;

            Console.WriteLine(s);

            return s;
        }