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(); } }
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(); } }
public IActionResult TurnReset([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 + "SNAPSHOT"); VisualBoardStore.KillBoard(gameId); var newboard = new Dictionary <string, string>(); foreach (var item in board) { newboard.Add(item.Key, item.Value); } VisualBoardStore.AddBoard(gameId, newboard); // overwrite it Response.Headers.Add("Access-Control-Allow-Origin", "*"); return(Ok()); } finally { s.Release(); } }
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(); } }
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(); } }
public IActionResult Selected([FromQuery] string gameId, [FromQuery] string loc, [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); 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, loc); VisualBoardStore.ReplaceHues(gameId, color, boardHues); string json = ""; json = "["; foreach (var spot in board) { json += "{\"loc\":\"" + spot.Key; json += "\",\"tok\":\"" + spot.Value; json += "\",\"hue\":\"" + boardHues[spot.Key]; // (spot.Key[0] == 'P' ? "0,255,0,0.7" : "255,0,0,0.7"); json += "\"},"; } json = json.Substring(0, json.Length - 1); json += "]"; //Response.Headers.Add("Access-Control-Allow-Origin", "https://hexagonalchess.online"); Response.Headers.Add("Access-Control-Allow-Origin", "*"); return(Ok(json)); } finally { s.Release(); } }
public IActionResult Board([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 (null == gameId || color == null) { return(BadRequest()); } MakeCertainGameExists(gameId); var board = VisualBoardStore.GameBoard(gameId); var hues = VisualBoardStore.TeamHues(gameId, color); // var hues = VisualBoardStore.ReplaceHues(gameid, color); string json = "["; foreach (var spot in board) { json += "{\"loc\":\"" + spot.Key; json += "\",\"tok\":\"" + spot.Value; string hue = "128,128,128,0.9"; if (spot.Key == "n0_n0") { hue = "0,0,0,1.0"; } if (hues.ContainsKey(spot.Key)) { hue = hues[spot.Key]; } json += "\",\"hue\":\"" + hue; json += "\"},"; } json = json.Substring(0, json.Length - 1); json += "]"; return(Ok(json)); } finally { s.Release(); } }
public IActionResult Events([FromQuery] string gameId) { Response.Headers.Add("Access-Control-Allow-Origin", "*"); System.Threading.Semaphore s = new System.Threading.Semaphore(1, 1, "COPS"); s.WaitOne(); try { if (gameId == null) { return(BadRequest()); } MakeCertainGameExists(gameId); using (var reader = new System.IO.StreamReader(Request.Body)) { var body = reader.ReadToEnd(); //JObject o = JObject.Parse(body); JArray a = JArray.Parse(body); var item = a.First; IList <RootObject> eventy = a.ToObject <IList <RootObject> >(); Console.WriteLine(a); // IList<Person> person = a.ToObject<IList<Person>>(); // Console.WriteLine(person[0].Name); // John Smith // Console.WriteLine(person[1].Name); // Mike Smith } var board = VisualBoardStore.GameBoard(gameId); return(Ok()); } finally { s.Release(); } }
public IActionResult Pieces([FromBody] Move move) { System.Threading.Semaphore s = new System.Threading.Semaphore(1, 1, "COPS"); s.WaitOne(); try { MakeCertainGameExists(move.gameId); var board = VisualBoardStore.GameBoard(move.gameId); // allPieces[move.gameId]; string movefrom = move.moveFrom.Substring(0, 5); /* not happening cuz i can't click a piece as my targ. * if (board[move.moveTo][1] == 'Q') * if (board[movefrom][1] == 'K') * { * string tmp = board[move.moveTo]; * board[move.moveTo] = board[movefrom]; * board[movefrom] = tmp; * } */ if (board[move.moveTo] == "XX") { board[move.moveTo] = board[movefrom]; board[movefrom] = "XX"; } else { // you're moving to a spot that contains a piece. // is it an opponent piece? // well i don't care. // if I'm attacking a piece, i'd be so cool if i: // 1. moved that piece to limbo, // 2. moved same-color same-piece FROM limbo if possible. // (if portal is occupied, then it's not possible). } Response.Headers.Add("Access-Control-Allow-Origin", "*"); return(Ok()); } finally { s.Release(); } }
public string InternalSelected(string gameId, string loc, string color) { if (null == gameId || color == null) { return(null); } MakeCertainGameExists(gameId); var board = VisualBoardStore.GameBoard(gameId); 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, loc); VisualBoardStore.ReplaceTeamHues(gameId, color, boardHues); string json = ""; json = "["; foreach (var spot in board) { json += "{\"loc\":\"" + spot.Key; json += "\",\"tok\":\"" + spot.Value; json += "\",\"hue\":\"" + boardHues[spot.Key]; // (spot.Key[0] == 'P' ? "0,255,0,0.7" : "255,0,0,0.7"); json += "\"},"; } json = json.Substring(0, json.Length - 1); json += "]"; return(json); }
public IActionResult Pieces([FromBody] Move move) { Response.Headers.Add("Access-Control-Allow-Origin", "*"); System.Threading.Semaphore s = new System.Threading.Semaphore(1, 1, "COPS"); s.WaitOne(); try { if (move.gameId == null) { return(BadRequest()); } MakeCertainGameExists(move.gameId); var board = VisualBoardStore.GameBoard(move.gameId); // allPieces[move.gameId]; string movefromWithoutPieceNoise = move.moveFrom.Substring(0, 5); /* not happening cuz i can't click a piece as my targ. * if (board[move.moveTo][1] == 'Q') * if (board[movefrom][1] == 'K') * { * string tmp = board[move.moveTo]; * board[move.moveTo] = board[movefrom]; * board[movefrom] = tmp; * } */ string justCheckinSrc = board[movefromWithoutPieceNoise]; string justCheckinDest = board[move.moveTo]; if (justCheckinSrc == "XX") { return(Ok()); } if (board[move.moveTo] == "XX") { board[move.moveTo] = board[movefromWithoutPieceNoise]; board[movefromWithoutPieceNoise] = "XX"; } else { // you're moving to a spot that contains a piece. // i'm pretty sure will requires that the target is an opponent piece. // so just do the easy here and shove that piece off and take its spot. // and put a piece of mine in the center if it's unoccupied. // still, if it's my color, then leave it. if (board[move.moveTo][0] != board[movefromWithoutPieceNoise][0]) // different color? { // ok, it's a different color. move that target off to the limbo. // but I wanna know what kinda piece it is first. char attackColor = board[movefromWithoutPieceNoise][0]; char pieceKilled = board[move.moveTo][1]; AddPieceToLimbo(board, board[move.moveTo]); MoveFromLimboIfPossible(board, attackColor, pieceKilled); // if(move.moveTo == "n0_n0") board[move.moveTo] = board[movefromWithoutPieceNoise]; board[movefromWithoutPieceNoise] = "XX"; } } InternalSelected(move.gameId, move.moveTo, move.color); // wanna see the options where the piece lands return(Ok()); } finally { s.Release(); } }