void Run(TextReader input, TextWriter output) { var ser = new BoardSerializer(); var brd = ser.Deserialize(input); int p = Convert.ToInt32(input.ReadLine()); var currentColor = (ChessColor)Enum.Parse(typeof(ChessColor), input.ReadLine()); for (int i = 0; i < p; i++) { var crds = input.ReadLine().Split('-').Select(x => new { h = x[0] - 'a', v = x[1] - '1' }).ToArray(); var outcome = brd.SmellMove(currentColor, crds[0].h, crds[0].v, crds[1].h, crds[1].v); output.WriteLine(outcome); if (outcome != MoveSmell.Incorrect) { brd.PerformMove(crds[0].h, crds[0].v, crds[1].h, crds[1].v); currentColor = currentColor.Switch(); } if (outcome == MoveSmell.Draw || outcome == MoveSmell.Incorrect || outcome == MoveSmell.Mate) { break; } } output.WriteLine(); ser.Serialize(brd, output); }
public static BaseSource ConvertToSource(StageComponent comp) { if (comp is VideoMedia media) { if (media.FromYoutube) { return(new YoutubeSource(media.Identifier, media.Thumbnail.OriginalString, media.DownloadID)); } else { return(new ExternalVideoSource() { FullPath = media.Path, Id = media.Id, ThumbnailUri = media.Thumbnail.OriginalString, Title = media.Identifier, }); } } else if (comp is LightComponent lightComponent) { return(new LightSource() { Id = lightComponent.Id, MovingData = BoardSerializer.SerializeToString(lightComponent.SetterBoard), Title = lightComponent.Identifier, }); } return(null); }
public IBoard Get() { var localBoard = _game.CreateBoard(); HttpContext.Session.Set("LocalB", BoardSerializer.SerializeObject(localBoard)); return(localBoard); }
public LightComponent(SetterBoard setterBoard) : this() { SetterBoard = setterBoard; Identifier = setterBoard.Identifier; Time = TimeSpan.FromSeconds(20); Thumbnail = new Uri("pack://application:,,,/Delight;component/Resources/defaultLightImage.png"); Id = Crc32.GetHashFromString(BoardSerializer.SerializeToString(setterBoard)); }
public PlaceBattleshipResponse AddBattleShip([FromBody] PlaceBattleshipRequest request) { if (request == null) { throw new ArgumentException("The request object is null."); } try { var orientation = (OrientationType)Enum.Parse(typeof(OrientationType), request.Orientation); byte[] deserial; bool canRead = HttpContext.Session.TryGetValue("LocalB", out deserial); if (canRead) { var localB = BoardSerializer.DeSerializeObject(deserial); bool result = _game.AddBattleship(localB, new BoardCell() { RowCoordinate = request.RowCoordinate, ColumnCoordinate = request.ColumCoordinate }, new Battleship() { Orientation = orientation, Width = request.Width }); HttpContext.Session.Set("LocalB", BoardSerializer.SerializeObject(localB)); return(new PlaceBattleshipResponse() { Result = result, Board = localB }); } //Force the player to create new game before placing battleship throw new HttpResponseException { HttpStatusCode = HttpStatusCode.NotFound, HttpResponseMessage = "The game board has not been created. Please create a game board before attacking." }; } catch (Exception ex) { throw new HttpResponseException { HttpStatusCode = HttpStatusCode.InternalServerError, HttpResponseMessage = ex.Message }; } }
public AttackResponse Attack([FromBody] AttackRequest request) { if (request == null) { throw new ArgumentException("The request object is null."); } try { byte[] deserial; bool canRead = HttpContext.Session.TryGetValue("LocalB", out deserial); if (canRead) { var localB = BoardSerializer.DeSerializeObject(deserial); var HitOrMiss = _game.Attack(localB, new BoardCell() { RowCoordinate = request.RowCoordinate, ColumnCoordinate = request.ColumnCoordinate }); HttpContext.Session.Set("LocalB", BoardSerializer.SerializeObject(localB)); return(new AttackResponse() { Board = localB, Result = Enum.GetName(typeof(AttackResult), HitOrMiss) }); } //Force the player to create new game before placing battleship throw new HttpResponseException { HttpStatusCode = HttpStatusCode.NotFound, HttpResponseMessage = "The game board has not been created. Please create a game board before attacking." }; } catch (Exception ex) { throw new HttpResponseException { HttpStatusCode = HttpStatusCode.InternalServerError, HttpResponseMessage = ex.Message }; } }
public static StageComponent ConvertToComponent(BaseSource source) { if (source is ExternalVideoSource externalVideoSource) { return(new VideoMedia() { FromYoutube = false, Id = source.Id, Path = externalVideoSource.FullPath, Time = MediaTools.GetMediaDuration(externalVideoSource.FullPath), Thumbnail = ((BitmapImage)MediaTools.GetMediaThumbnail(externalVideoSource.FullPath)).UriSource, Identifier = externalVideoSource.Title, }); } else if (source is YoutubeSource youtubeSource) { source.Download(0); var item = FileCacheDictionary.GetPathFromId(source.Id); string path = Path.Combine(DelightAppPath, "External Sources Cache", item.Value.Item1); return(new VideoMedia() { Identifier = item.Key, Time = MediaTools.GetMediaDuration(path), Path = path, Thumbnail = new Uri(source.ThumbnailUri), FromYoutube = true, DownloadID = source.Id, Id = source.Id, }); } else if (source is LightSource lightSource) { return(new LightComponent(BoardSerializer.LoadFromString(lightSource.MovingData))); } return(null); }
public override void Initialise(BoardSerializer bs) { }
public abstract void Initialise(BoardSerializer bs);