Esempio n. 1
0
        public IActionResult TurnConcluded([FromQuery] string gameId, [FromQuery] string color)
        {
            System.Threading.Semaphore s = new System.Threading.Semaphore(1, 1, "COPS"); s.WaitOne();
            try
            {
                if (gameId == null)
                {
                    return(BadRequest());
                }
                MakeCertainGameExists(gameId);
                var board = VisualBoardStore.GameBoard(gameId);
                // just store that last board state in case someone hits turn reset.
                if (VisualBoardStore.ContainsGame(gameId + "SNAPSHOT"))
                {
                    VisualBoardStore.KillBoard(gameId + "SNAPSHOT"); // if any...
                }
                var newboard = new Dictionary <string, string>();
                foreach (var item in board)
                {
                    newboard.Add(item.Key, item.Value);
                }
                VisualBoardStore.AddBoard(gameId + "SNAPSHOT", newboard);

                Response.Headers.Add("Access-Control-Allow-Origin", "*");
                return(Ok());
            }
            finally { s.Release(); }
        }
Esempio n. 2
0
 public IActionResult Back([FromQuery] string gameId)
 {
     System.Threading.Semaphore s = new System.Threading.Semaphore(1, 1, "COPS"); s.WaitOne();
     try
     {
         if (gameId == null)
         {
             return(BadRequest());
         }
         MakeCertainGameExists(gameId);
         for (int iStep = 1000; iStep > 99; iStep--)
         {
             if (VisualBoardStore.ContainsGame(gameId + iStep.ToString()))
             {
                 // when the snapshot board matches the current board, we go one past that one...
                 var snapBoard = VisualBoardStore.GameBoard(gameId + iStep);
                 var curBoard  = VisualBoardStore.GameBoard(gameId);
                 if (NoDifferences(curBoard, snapBoard))
                 {
                     iStep--;
                     if (iStep == 99)
                     {
                         break;
                     }
                     var newboard = FreshCopyOf(VisualBoardStore.GameBoard(gameId + iStep.ToString()));
                     VisualBoardStore.KillBoard(gameId);
                     VisualBoardStore.AddBoard(gameId, newboard);
                     break;
                 }
             }
         }
         return(Ok());
     }
     finally { s.Release(); }
 }
Esempio n. 3
0
        public IActionResult TurnReset([FromQuery] string gameId, [FromQuery] string color)
        {
            Response.Headers.Add("Access-Control-Allow-Origin", "*");
            System.Threading.Semaphore s = new System.Threading.Semaphore(1, 1, "COPS"); s.WaitOne();
            try
            {
                if (gameId == null || color == null)
                {
                    return(BadRequest());
                }
                MakeCertainGameExists(gameId);

                string highestGameSnapshot = null;
                for (int iStep = 100; iStep < 1000; iStep++)
                {
                    if (VisualBoardStore.ContainsGame(gameId + iStep.ToString()))
                    {
                        highestGameSnapshot = gameId + iStep.ToString();
                        continue;
                    }
                    // Set the board to the highest game snapshot we have.
                    var board    = VisualBoardStore.GameBoard(highestGameSnapshot);
                    var newboard = FreshCopyOf(board);
                    VisualBoardStore.KillBoard(gameId);
                    VisualBoardStore.AddBoard(gameId, newboard); // overwrite it
                }
                return(Ok());
            }
            finally { s.Release(); }
        }
Esempio n. 4
0
        public IActionResult TurnConcluded([FromQuery] string gameId, [FromQuery] string color)
        {
            Response.Headers.Add("Access-Control-Allow-Origin", "*");
            System.Threading.Semaphore s = new System.Threading.Semaphore(1, 1, "COPS"); s.WaitOne();
            try
            {
                if (gameId == null || color == null)
                {
                    return(BadRequest());
                }
                MakeCertainGameExists(gameId);

                var board = VisualBoardStore.GameBoard(gameId);

                // Some day this move will be validated, but for now, I just find the next sequential snapshot slot and store the board there.
                // just store that last board state in case someone hits turn reset.

                var newboard = FreshCopyOf(board);

                for (int iStep = 100; iStep < 1000; iStep++)
                {
                    if (VisualBoardStore.ContainsGame(gameId + iStep.ToString()))
                    {
                        continue;
                    }

                    // ok we found this game snapshot name
                    VisualBoardStore.AddBoard(gameId + iStep.ToString(), newboard);
                    break;
                }

                Dictionary <string, string> boardHues = new Dictionary <string, string>();
                foreach (var pos in board.Keys)
                {
                    if (pos == "n0_n0")
                    {
                        boardHues.Add(pos, "0,0,0,1.0"); // black center
                    }
                    else
                    {
                        boardHues.Add(pos, "128,128,128,0.9"); // gray by default
                    }
                }
                HexC.Program.LightUpWillsBoard(board, boardHues, null);
                VisualBoardStore.ReplaceTeamHues(gameId, "black", boardHues);
                VisualBoardStore.ReplaceTeamHues(gameId, "white", boardHues);
                VisualBoardStore.ReplaceTeamHues(gameId, "tan", boardHues);

                // Store the color of the clicker party.
                VisualBoardStore.LastReportedTurnEnd(gameId, color);


                return(Ok());
            }
            finally { s.Release(); }
        }
Esempio n. 5
0
        void MakeCertainGameExists(string id)
        {
            if (VisualBoardStore.ContainsGame(id))
            {
                return;
            }

            Dictionary <string, string> board = new Dictionary <string, string>();


            board.Add("n0_n0", "XX");
            board.Add("n0_n1", "XX");
            board.Add("n0_n2", "XX");
            board.Add("n0_n3", "XX");
            board.Add("n0_n4", "XX");
            board.Add("n0_n5", "XX");
            board.Add("n0_p1", "XX");
            board.Add("n0_p2", "XX");
            board.Add("n0_p3", "XX");
            board.Add("n0_p4", "XX");
            board.Add("n0_p5", "XX");
            board.Add("n1_n0", "XX");
            board.Add("n1_p1", "XX");
            board.Add("n2_n0", "XX");
            board.Add("n2_p1", "XX");
            board.Add("n2_p2", "XX");
            board.Add("n3_n0", "XX");
            board.Add("n3_p1", "XX");
            board.Add("n3_p2", "XX");
            board.Add("n3_p3", "XX");
            board.Add("n4_n2", "XX");
            board.Add("n4_p1", "XX");
            board.Add("n4_p2", "XX");
            board.Add("n4_p3", "XX");
            board.Add("n4_p4", "XX");
            board.Add("n5_n0", "XX");
            board.Add("n5_n1", "XX");
            board.Add("n5_n2", "XX");
            board.Add("n5_p1", "XX");
            board.Add("n5_p2", "XX");
            board.Add("n5_p3", "XX");
            board.Add("n5_p4", "XX");
            board.Add("n5_p5", "XX");
            board.Add("p1_n0", "XX");
            board.Add("p1_n1", "XX");
            board.Add("p1_n2", "XX");
            board.Add("p1_n3", "XX");
            board.Add("p1_n4", "XX");
            board.Add("p1_n5", "XX");
            board.Add("p1_p1", "XX");
            board.Add("p1_p2", "XX");
            board.Add("p1_p3", "XX");
            board.Add("p1_p4", "XX");
            board.Add("p1_p5", "XX");
            board.Add("p2_n0", "XX");
            board.Add("p2_n2", "XX");
            board.Add("p2_n3", "XX");
            board.Add("p2_n4", "XX");
            board.Add("p2_n5", "XX");
            board.Add("p2_p1", "XX");
            board.Add("p2_p2", "XX");
            board.Add("p2_p3", "XX");
            board.Add("p2_p4", "XX");
            board.Add("p3_n0", "XX");
            board.Add("n4_n0", "XX");
            board.Add("p3_n3", "XX");
            board.Add("p3_n4", "XX");
            board.Add("p3_n5", "XX");
            board.Add("p3_p1", "XX");
            board.Add("p3_p2", "XX");
            board.Add("p3_p3", "XX");
            board.Add("p3_p4", "XX");
            board.Add("p4_n0", "XX");
            board.Add("p4_n4", "XX");
            board.Add("p4_n5", "XX");
            board.Add("p4_p1", "XX");
            board.Add("p4_p2", "XX");
            board.Add("p5_n0", "XX");
            board.Add("p5_n5", "XX");
            board.Add("p5_p3", "XX");
            board.Add("WV_01", "XX");
            board.Add("WV_02", "XX");
            board.Add("WV_03", "XX");
            board.Add("WV_04", "XX");
            board.Add("WV_05", "XX");
            board.Add("WV_06", "XX");
            board.Add("WV_07", "XX");
            board.Add("WV_08", "XX");
            board.Add("WV_09", "XX");
            board.Add("WV_10", "XX");
            board.Add("WV_11", "XX");
            board.Add("WV_12", "XX");
            board.Add("WV_13", "XX");
            board.Add("TV_01", "XX");
            board.Add("TV_02", "XX");
            board.Add("TV_03", "XX");
            board.Add("TV_04", "XX");
            board.Add("TV_05", "XX");
            board.Add("TV_06", "XX");
            board.Add("TV_07", "XX");
            board.Add("TV_08", "XX");
            board.Add("TV_09", "XX");
            board.Add("TV_10", "XX");
            board.Add("TV_11", "XX");
            board.Add("TV_12", "XX");
            board.Add("TV_13", "XX");
            board.Add("BV_01", "XX");
            board.Add("BV_02", "XX");
            board.Add("BV_03", "XX");
            board.Add("BV_04", "XX");
            board.Add("BV_05", "XX");
            board.Add("BV_06", "XX");
            board.Add("BV_07", "XX");
            board.Add("BV_08", "XX");
            board.Add("BV_09", "XX");
            board.Add("BV_10", "XX");
            board.Add("BV_11", "XX");
            board.Add("BV_12", "XX");
            board.Add("BV_13", "XX");

            board.Add("n3_n2", "TK");
            board.Add("n3_p5", "WK");
            board.Add("p5_n2", "BK");



            //    board.Add("n1_p2", "WC");
            //   board.Add("n1_n1", "WP");

            board.Add("n1_p2", "WP");
            board.Add("n1_n1", "TP");
            board.Add("n1_n2", "TP");
            board.Add("n1_n3", "TE");
            board.Add("n1_n4", "TC");
            board.Add("n1_p3", "WP");
            board.Add("n1_p4", "WE");
            board.Add("n1_p5", "WC");
            board.Add("n2_n1", "TP");
            board.Add("n2_n2", "TE");
            board.Add("n2_n3", "TQ");
            board.Add("n2_p3", "WP");
            board.Add("n2_p4", "WE");
            board.Add("n2_p5", "WQ");
            board.Add("n3_n1", "TE");
            board.Add("n3_p4", "WE");
            board.Add("n4_n1", "TC");
            board.Add("n4_p5", "WC");
            board.Add("p2_n1", "BP");
            board.Add("p3_n1", "BP");
            board.Add("p3_n2", "BP");
            board.Add("p4_n1", "BE");
            board.Add("p4_n2", "BE");
            board.Add("p4_n3", "BE");
            board.Add("p5_n1", "BC");
            board.Add("p5_n3", "BQ");
            board.Add("p5_n4", "BC");

            VisualBoardStore.AddBoard(id, board);
            VisualBoardStore.AddBoard(id + "SNAPSHOT", board);

            // allHues.Add(id, new Dictionary<string, string>());
        }