From b149e0a70a5447ad874a63a8bb31bf617516c059 Mon Sep 17 00:00:00 2001 From: AminHP Date: Sun, 29 Sep 2019 00:17:36 +0330 Subject: [PATCH] Add C# Client --- CSharpClient/.gitattributes | 63 ++ CSharpClient/.gitignore | 340 +++++++ CSharpClient/Game.sln | 25 + CSharpClient/Game/AI.cs | 125 +++ CSharpClient/Game/Game.csproj | 18 + CSharpClient/Game/KS/Commands.cs | 215 +++++ CSharpClient/Game/KS/KSObject.cs | 12 + CSharpClient/Game/KS/Models.cs | 1437 ++++++++++++++++++++++++++++++ CSharpClient/Game/KS/commands.ks | 26 + CSharpClient/Game/KS/models.ks | 92 ++ CSharpClient/Game/Program.cs | 24 + CSharpClient/Game/gamecfg.json | 21 + 12 files changed, 2398 insertions(+) create mode 100644 CSharpClient/.gitattributes create mode 100644 CSharpClient/.gitignore create mode 100644 CSharpClient/Game.sln create mode 100644 CSharpClient/Game/AI.cs create mode 100644 CSharpClient/Game/Game.csproj create mode 100644 CSharpClient/Game/KS/Commands.cs create mode 100644 CSharpClient/Game/KS/KSObject.cs create mode 100644 CSharpClient/Game/KS/Models.cs create mode 100644 CSharpClient/Game/KS/commands.ks create mode 100644 CSharpClient/Game/KS/models.ks create mode 100644 CSharpClient/Game/Program.cs create mode 100644 CSharpClient/Game/gamecfg.json diff --git a/CSharpClient/.gitattributes b/CSharpClient/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/CSharpClient/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/CSharpClient/.gitignore b/CSharpClient/.gitignore new file mode 100644 index 0000000..4ce6fdd --- /dev/null +++ b/CSharpClient/.gitignore @@ -0,0 +1,340 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- Backup*.rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb \ No newline at end of file diff --git a/CSharpClient/Game.sln b/CSharpClient/Game.sln new file mode 100644 index 0000000..15dfb7b --- /dev/null +++ b/CSharpClient/Game.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29025.244 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game", "Game\Game.csproj", "{8F1FBFF4-15DA-4083-A247-D60E1E0BDB4C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8F1FBFF4-15DA-4083-A247-D60E1E0BDB4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8F1FBFF4-15DA-4083-A247-D60E1E0BDB4C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8F1FBFF4-15DA-4083-A247-D60E1E0BDB4C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8F1FBFF4-15DA-4083-A247-D60E1E0BDB4C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9C7ED05B-19BE-407A-9D99-B9F58AF30F83} + EndGlobalSection +EndGlobal diff --git a/CSharpClient/Game/AI.cs b/CSharpClient/Game/AI.cs new file mode 100644 index 0000000..3bff867 --- /dev/null +++ b/CSharpClient/Game/AI.cs @@ -0,0 +1,125 @@ +using System; + +using KoalaTeam.Chillin.Client; +using KS; +using KS.Commands; +using KS.Models; + +using KSObject = KS.KSObject; + +namespace Game +{ + public class AI : RealtimeAI + { + private readonly Random random = new Random(); + + public AI(World world) : base(world) + { + } + + public override void Initialize() + { + Console.WriteLine("initialize"); + } + + public override void Decide() + { + Console.WriteLine("decide"); + + if (this.MySide == "Police") + { + foreach (var police in this.World.Polices) + { + if (police.Status == EAgentStatus.Dead) + continue; + + bool doingBombOperation = police.DefusionRemainingTime != -1; + if (doingBombOperation) + { + Console.WriteLine("Agent[" + police.Id + "]: " + "Continue Bomb Operation"); + continue; + } + + ECommandDirection? bombsiteDirection = FindBombsiteDirection(police.Position); + if (bombsiteDirection == null) + { + Console.WriteLine("Agent[" + police.Id + "]: " + "Random Move"); + var randDir = (ECommandDirection)random.Next(Enum.GetNames(typeof(ECommandDirection)).Length); + Move(police.Id, randDir); + } + else + { + Console.WriteLine("Agent[" + police.Id + "]: " + "Start Bomb Operation"); + Defuse(police.Id, bombsiteDirection.Value); + } + } + } + else + { + foreach (var terrorist in this.World.Terrorists) + { + if (terrorist.Status == EAgentStatus.Dead) + continue; + + bool doingBombOperation = terrorist.PlantingRemainingTime != -1; + if (doingBombOperation) + { + Console.WriteLine("Agent[" + terrorist.Id + "]: " + "Continue Bomb Operation"); + continue; + } + + ECommandDirection? bombsiteDirection = FindBombsiteDirection(terrorist.Position); + if (bombsiteDirection == null) + { + Console.WriteLine("Agent[" + terrorist.Id + "]: " + "Random Move"); + var randDir = (ECommandDirection)random.Next(Enum.GetNames(typeof(ECommandDirection)).Length); + Move(terrorist.Id, randDir); + } + else + { + Console.WriteLine("Agent[" + terrorist.Id + "]: " + "Start Bomb Operation"); + Plant(terrorist.Id, bombsiteDirection.Value); + } + } + } + } + + + public void Move(int? agentId, ECommandDirection moveDirection) + { + this.SendCommand(new Move() { Id = agentId, Direction = moveDirection }); + } + + public void Plant(int? agentId, ECommandDirection bombsiteDirection) + { + this.SendCommand(new PlantBomb() { Id = agentId, Direction = bombsiteDirection }); + } + + public void Defuse(int? agentId, ECommandDirection bombsiteDirection) + { + this.SendCommand(new DefuseBomb() { Id = agentId, Direction = bombsiteDirection }); + } + + + private ECommandDirection? FindBombsiteDirection(Position position) + { + if ((World.Board[(int)position.Y - 1][(int)position.X].Value >= ECell.SmallBombSite) && + (World.Board[(int)position.Y - 1][(int)position.X].Value <= ECell.VastBombSite)) + return ECommandDirection.Up; + + if ((World.Board[(int)position.Y][(int)position.X + 1].Value >= ECell.SmallBombSite) && + (World.Board[(int)position.Y][(int)position.X + 1].Value <= ECell.VastBombSite)) + return ECommandDirection.Right; + + if ((World.Board[(int)position.Y + 1][(int)position.X].Value >= ECell.SmallBombSite) && + (World.Board[(int)position.Y + 1][(int)position.X].Value <= ECell.VastBombSite)) + return ECommandDirection.Down; + + if ((World.Board[(int)position.Y][(int)position.X - 1].Value >= ECell.SmallBombSite) && + (World.Board[(int)position.Y][(int)position.X - 1].Value <= ECell.VastBombSite)) + return ECommandDirection.Left; + + return null; + } + } +} diff --git a/CSharpClient/Game/Game.csproj b/CSharpClient/Game/Game.csproj new file mode 100644 index 0000000..0547b13 --- /dev/null +++ b/CSharpClient/Game/Game.csproj @@ -0,0 +1,18 @@ + + + + Exe + netcoreapp2.1 + + + + + + + + + PreserveNewest + + + + diff --git a/CSharpClient/Game/KS/Commands.cs b/CSharpClient/Game/KS/Commands.cs new file mode 100644 index 0000000..59c262f --- /dev/null +++ b/CSharpClient/Game/KS/Commands.cs @@ -0,0 +1,215 @@ +using System; +using System.Linq; +using System.Collections.Generic; + +namespace KS.Commands +{ + public enum ECommandDirection + { + Up = 0, + Right = 1, + Down = 2, + Left = 3, + } + + public partial class Move : KSObject + { + public int? Id { get; set; } + public ECommandDirection? Direction { get; set; } + + + public Move() + { + } + + public new const string NameStatic = "Move"; + + public override string Name() => "Move"; + + public override byte[] Serialize() + { + List s = new List(); + + // serialize Id + s.Add((byte)((Id == null) ? 0 : 1)); + if (Id != null) + { + s.AddRange(BitConverter.GetBytes((int)Id)); + } + + // serialize Direction + s.Add((byte)((Direction == null) ? 0 : 1)); + if (Direction != null) + { + s.Add((byte)((sbyte)Direction)); + } + + return s.ToArray(); + } + + public override uint Deserialize(byte[] s, uint offset = 0) + { + // deserialize Id + byte tmp0; + tmp0 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp0 == 1) + { + Id = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + Id = null; + + // deserialize Direction + byte tmp1; + tmp1 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp1 == 1) + { + sbyte tmp2; + tmp2 = (sbyte)s[(int)offset]; + offset += sizeof(sbyte); + Direction = (ECommandDirection)tmp2; + } + else + Direction = null; + + return offset; + } + } + + public partial class PlantBomb : KSObject + { + public int? Id { get; set; } + public ECommandDirection? Direction { get; set; } + + + public PlantBomb() + { + } + + public new const string NameStatic = "PlantBomb"; + + public override string Name() => "PlantBomb"; + + public override byte[] Serialize() + { + List s = new List(); + + // serialize Id + s.Add((byte)((Id == null) ? 0 : 1)); + if (Id != null) + { + s.AddRange(BitConverter.GetBytes((int)Id)); + } + + // serialize Direction + s.Add((byte)((Direction == null) ? 0 : 1)); + if (Direction != null) + { + s.Add((byte)((sbyte)Direction)); + } + + return s.ToArray(); + } + + public override uint Deserialize(byte[] s, uint offset = 0) + { + // deserialize Id + byte tmp3; + tmp3 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp3 == 1) + { + Id = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + Id = null; + + // deserialize Direction + byte tmp4; + tmp4 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp4 == 1) + { + sbyte tmp5; + tmp5 = (sbyte)s[(int)offset]; + offset += sizeof(sbyte); + Direction = (ECommandDirection)tmp5; + } + else + Direction = null; + + return offset; + } + } + + public partial class DefuseBomb : KSObject + { + public int? Id { get; set; } + public ECommandDirection? Direction { get; set; } + + + public DefuseBomb() + { + } + + public new const string NameStatic = "DefuseBomb"; + + public override string Name() => "DefuseBomb"; + + public override byte[] Serialize() + { + List s = new List(); + + // serialize Id + s.Add((byte)((Id == null) ? 0 : 1)); + if (Id != null) + { + s.AddRange(BitConverter.GetBytes((int)Id)); + } + + // serialize Direction + s.Add((byte)((Direction == null) ? 0 : 1)); + if (Direction != null) + { + s.Add((byte)((sbyte)Direction)); + } + + return s.ToArray(); + } + + public override uint Deserialize(byte[] s, uint offset = 0) + { + // deserialize Id + byte tmp6; + tmp6 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp6 == 1) + { + Id = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + Id = null; + + // deserialize Direction + byte tmp7; + tmp7 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp7 == 1) + { + sbyte tmp8; + tmp8 = (sbyte)s[(int)offset]; + offset += sizeof(sbyte); + Direction = (ECommandDirection)tmp8; + } + else + Direction = null; + + return offset; + } + } +} // namespace KS.Commands diff --git a/CSharpClient/Game/KS/KSObject.cs b/CSharpClient/Game/KS/KSObject.cs new file mode 100644 index 0000000..31f165a --- /dev/null +++ b/CSharpClient/Game/KS/KSObject.cs @@ -0,0 +1,12 @@ +using System; + +namespace KS +{ + public abstract partial class KSObject + { + public const string NameStatic = ""; + public abstract string Name(); + public abstract byte[] Serialize(); + public abstract uint Deserialize(byte[] s, uint offset = 0); + } +} // namespace KS diff --git a/CSharpClient/Game/KS/Models.cs b/CSharpClient/Game/KS/Models.cs new file mode 100644 index 0000000..e505046 --- /dev/null +++ b/CSharpClient/Game/KS/Models.cs @@ -0,0 +1,1437 @@ +using System; +using System.Linq; +using System.Collections.Generic; + +namespace KS.Models +{ + public enum ECell + { + Empty = 0, + SmallBombSite = 1, + MediumBombSite = 2, + LargeBombSite = 3, + VastBombSite = 4, + Wall = 5, + } + + public enum ESoundIntensity + { + Weak = 0, + Normal = 1, + Strong = 2, + } + + public enum EAgentStatus + { + Alive = 0, + Dead = 1, + } + + public partial class Constants : KSObject + { + public int? BombPlantingTime { get; set; } + public int? BombDefusionTime { get; set; } + public int? BombExplosionTime { get; set; } + public int? BombPlantingScore { get; set; } + public int? BombDefusionScore { get; set; } + public int? BombExplosionScore { get; set; } + public float? ScoreCoefficientSmallBombSite { get; set; } + public float? ScoreCoefficientMediumBombSite { get; set; } + public float? ScoreCoefficientLargeBombSite { get; set; } + public float? ScoreCoefficientVastBombSite { get; set; } + public int? TerroristVisionDistance { get; set; } + public int? TerroristDeathScore { get; set; } + public int? PoliceDeathScore { get; set; } + public int? PoliceVisionDistance { get; set; } + public Dictionary SoundRanges { get; set; } + public int? MaxCycles { get; set; } + + + public Constants() + { + } + + public new const string NameStatic = "Constants"; + + public override string Name() => "Constants"; + + public override byte[] Serialize() + { + List s = new List(); + + // serialize BombPlantingTime + s.Add((byte)((BombPlantingTime == null) ? 0 : 1)); + if (BombPlantingTime != null) + { + s.AddRange(BitConverter.GetBytes((int)BombPlantingTime)); + } + + // serialize BombDefusionTime + s.Add((byte)((BombDefusionTime == null) ? 0 : 1)); + if (BombDefusionTime != null) + { + s.AddRange(BitConverter.GetBytes((int)BombDefusionTime)); + } + + // serialize BombExplosionTime + s.Add((byte)((BombExplosionTime == null) ? 0 : 1)); + if (BombExplosionTime != null) + { + s.AddRange(BitConverter.GetBytes((int)BombExplosionTime)); + } + + // serialize BombPlantingScore + s.Add((byte)((BombPlantingScore == null) ? 0 : 1)); + if (BombPlantingScore != null) + { + s.AddRange(BitConverter.GetBytes((int)BombPlantingScore)); + } + + // serialize BombDefusionScore + s.Add((byte)((BombDefusionScore == null) ? 0 : 1)); + if (BombDefusionScore != null) + { + s.AddRange(BitConverter.GetBytes((int)BombDefusionScore)); + } + + // serialize BombExplosionScore + s.Add((byte)((BombExplosionScore == null) ? 0 : 1)); + if (BombExplosionScore != null) + { + s.AddRange(BitConverter.GetBytes((int)BombExplosionScore)); + } + + // serialize ScoreCoefficientSmallBombSite + s.Add((byte)((ScoreCoefficientSmallBombSite == null) ? 0 : 1)); + if (ScoreCoefficientSmallBombSite != null) + { + s.AddRange(BitConverter.GetBytes((float)ScoreCoefficientSmallBombSite)); + } + + // serialize ScoreCoefficientMediumBombSite + s.Add((byte)((ScoreCoefficientMediumBombSite == null) ? 0 : 1)); + if (ScoreCoefficientMediumBombSite != null) + { + s.AddRange(BitConverter.GetBytes((float)ScoreCoefficientMediumBombSite)); + } + + // serialize ScoreCoefficientLargeBombSite + s.Add((byte)((ScoreCoefficientLargeBombSite == null) ? 0 : 1)); + if (ScoreCoefficientLargeBombSite != null) + { + s.AddRange(BitConverter.GetBytes((float)ScoreCoefficientLargeBombSite)); + } + + // serialize ScoreCoefficientVastBombSite + s.Add((byte)((ScoreCoefficientVastBombSite == null) ? 0 : 1)); + if (ScoreCoefficientVastBombSite != null) + { + s.AddRange(BitConverter.GetBytes((float)ScoreCoefficientVastBombSite)); + } + + // serialize TerroristVisionDistance + s.Add((byte)((TerroristVisionDistance == null) ? 0 : 1)); + if (TerroristVisionDistance != null) + { + s.AddRange(BitConverter.GetBytes((int)TerroristVisionDistance)); + } + + // serialize TerroristDeathScore + s.Add((byte)((TerroristDeathScore == null) ? 0 : 1)); + if (TerroristDeathScore != null) + { + s.AddRange(BitConverter.GetBytes((int)TerroristDeathScore)); + } + + // serialize PoliceDeathScore + s.Add((byte)((PoliceDeathScore == null) ? 0 : 1)); + if (PoliceDeathScore != null) + { + s.AddRange(BitConverter.GetBytes((int)PoliceDeathScore)); + } + + // serialize PoliceVisionDistance + s.Add((byte)((PoliceVisionDistance == null) ? 0 : 1)); + if (PoliceVisionDistance != null) + { + s.AddRange(BitConverter.GetBytes((int)PoliceVisionDistance)); + } + + // serialize SoundRanges + s.Add((byte)((SoundRanges == null) ? 0 : 1)); + if (SoundRanges != null) + { + List tmp0 = new List(); + tmp0.AddRange(BitConverter.GetBytes((uint)SoundRanges.Count())); + while (tmp0.Count > 0 && tmp0.Last() == 0) + tmp0.RemoveAt(tmp0.Count - 1); + s.Add((byte)tmp0.Count); + s.AddRange(tmp0); + + foreach (var tmp1 in SoundRanges) + { + s.Add((byte)((tmp1.Key == null) ? 0 : 1)); + if (tmp1.Key != null) + { + s.Add((byte)((sbyte)tmp1.Key)); + } + + s.Add((byte)((tmp1.Value == null) ? 0 : 1)); + if (tmp1.Value != null) + { + s.AddRange(BitConverter.GetBytes((int)tmp1.Value)); + } + } + } + + // serialize MaxCycles + s.Add((byte)((MaxCycles == null) ? 0 : 1)); + if (MaxCycles != null) + { + s.AddRange(BitConverter.GetBytes((int)MaxCycles)); + } + + return s.ToArray(); + } + + public override uint Deserialize(byte[] s, uint offset = 0) + { + // deserialize BombPlantingTime + byte tmp2; + tmp2 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp2 == 1) + { + BombPlantingTime = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + BombPlantingTime = null; + + // deserialize BombDefusionTime + byte tmp3; + tmp3 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp3 == 1) + { + BombDefusionTime = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + BombDefusionTime = null; + + // deserialize BombExplosionTime + byte tmp4; + tmp4 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp4 == 1) + { + BombExplosionTime = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + BombExplosionTime = null; + + // deserialize BombPlantingScore + byte tmp5; + tmp5 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp5 == 1) + { + BombPlantingScore = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + BombPlantingScore = null; + + // deserialize BombDefusionScore + byte tmp6; + tmp6 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp6 == 1) + { + BombDefusionScore = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + BombDefusionScore = null; + + // deserialize BombExplosionScore + byte tmp7; + tmp7 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp7 == 1) + { + BombExplosionScore = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + BombExplosionScore = null; + + // deserialize ScoreCoefficientSmallBombSite + byte tmp8; + tmp8 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp8 == 1) + { + ScoreCoefficientSmallBombSite = BitConverter.ToSingle(s, (int)offset); + offset += sizeof(float); + } + else + ScoreCoefficientSmallBombSite = null; + + // deserialize ScoreCoefficientMediumBombSite + byte tmp9; + tmp9 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp9 == 1) + { + ScoreCoefficientMediumBombSite = BitConverter.ToSingle(s, (int)offset); + offset += sizeof(float); + } + else + ScoreCoefficientMediumBombSite = null; + + // deserialize ScoreCoefficientLargeBombSite + byte tmp10; + tmp10 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp10 == 1) + { + ScoreCoefficientLargeBombSite = BitConverter.ToSingle(s, (int)offset); + offset += sizeof(float); + } + else + ScoreCoefficientLargeBombSite = null; + + // deserialize ScoreCoefficientVastBombSite + byte tmp11; + tmp11 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp11 == 1) + { + ScoreCoefficientVastBombSite = BitConverter.ToSingle(s, (int)offset); + offset += sizeof(float); + } + else + ScoreCoefficientVastBombSite = null; + + // deserialize TerroristVisionDistance + byte tmp12; + tmp12 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp12 == 1) + { + TerroristVisionDistance = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + TerroristVisionDistance = null; + + // deserialize TerroristDeathScore + byte tmp13; + tmp13 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp13 == 1) + { + TerroristDeathScore = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + TerroristDeathScore = null; + + // deserialize PoliceDeathScore + byte tmp14; + tmp14 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp14 == 1) + { + PoliceDeathScore = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + PoliceDeathScore = null; + + // deserialize PoliceVisionDistance + byte tmp15; + tmp15 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp15 == 1) + { + PoliceVisionDistance = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + PoliceVisionDistance = null; + + // deserialize SoundRanges + byte tmp16; + tmp16 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp16 == 1) + { + byte tmp17; + tmp17 = (byte)s[(int)offset]; + offset += sizeof(byte); + byte[] tmp18 = new byte[sizeof(uint)]; + Array.Copy(s, offset, tmp18, 0, tmp17); + offset += tmp17; + uint tmp19; + tmp19 = BitConverter.ToUInt32(tmp18, (int)0); + + SoundRanges = new Dictionary(); + for (uint tmp20 = 0; tmp20 < tmp19; tmp20++) + { + ESoundIntensity? tmp21; + byte tmp23; + tmp23 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp23 == 1) + { + sbyte tmp24; + tmp24 = (sbyte)s[(int)offset]; + offset += sizeof(sbyte); + tmp21 = (ESoundIntensity)tmp24; + } + else + tmp21 = null; + + int? tmp22; + byte tmp25; + tmp25 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp25 == 1) + { + tmp22 = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + tmp22 = null; + + SoundRanges[tmp21] = tmp22; + } + } + else + SoundRanges = null; + + // deserialize MaxCycles + byte tmp26; + tmp26 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp26 == 1) + { + MaxCycles = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + MaxCycles = null; + + return offset; + } + } + + public partial class Position : KSObject + { + public int? X { get; set; } + public int? Y { get; set; } + + + public Position() + { + } + + public new const string NameStatic = "Position"; + + public override string Name() => "Position"; + + public override byte[] Serialize() + { + List s = new List(); + + // serialize X + s.Add((byte)((X == null) ? 0 : 1)); + if (X != null) + { + s.AddRange(BitConverter.GetBytes((int)X)); + } + + // serialize Y + s.Add((byte)((Y == null) ? 0 : 1)); + if (Y != null) + { + s.AddRange(BitConverter.GetBytes((int)Y)); + } + + return s.ToArray(); + } + + public override uint Deserialize(byte[] s, uint offset = 0) + { + // deserialize X + byte tmp27; + tmp27 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp27 == 1) + { + X = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + X = null; + + // deserialize Y + byte tmp28; + tmp28 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp28 == 1) + { + Y = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + Y = null; + + return offset; + } + } + + public partial class Bomb : KSObject + { + public Position Position { get; set; } + public int? ExplosionRemainingTime { get; set; } + public int? PlanterId { get; set; } + public int? DefuserId { get; set; } + + + public Bomb() + { + } + + public new const string NameStatic = "Bomb"; + + public override string Name() => "Bomb"; + + public override byte[] Serialize() + { + List s = new List(); + + // serialize Position + s.Add((byte)((Position == null) ? 0 : 1)); + if (Position != null) + { + s.AddRange(Position.Serialize()); + } + + // serialize ExplosionRemainingTime + s.Add((byte)((ExplosionRemainingTime == null) ? 0 : 1)); + if (ExplosionRemainingTime != null) + { + s.AddRange(BitConverter.GetBytes((int)ExplosionRemainingTime)); + } + + // serialize PlanterId + s.Add((byte)((PlanterId == null) ? 0 : 1)); + if (PlanterId != null) + { + s.AddRange(BitConverter.GetBytes((int)PlanterId)); + } + + // serialize DefuserId + s.Add((byte)((DefuserId == null) ? 0 : 1)); + if (DefuserId != null) + { + s.AddRange(BitConverter.GetBytes((int)DefuserId)); + } + + return s.ToArray(); + } + + public override uint Deserialize(byte[] s, uint offset = 0) + { + // deserialize Position + byte tmp29; + tmp29 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp29 == 1) + { + Position = new Position(); + offset = Position.Deserialize(s, offset); + } + else + Position = null; + + // deserialize ExplosionRemainingTime + byte tmp30; + tmp30 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp30 == 1) + { + ExplosionRemainingTime = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + ExplosionRemainingTime = null; + + // deserialize PlanterId + byte tmp31; + tmp31 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp31 == 1) + { + PlanterId = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + PlanterId = null; + + // deserialize DefuserId + byte tmp32; + tmp32 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp32 == 1) + { + DefuserId = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + DefuserId = null; + + return offset; + } + } + + public partial class Terrorist : KSObject + { + public int? Id { get; set; } + public Position Position { get; set; } + public int? PlantingRemainingTime { get; set; } + public List FootstepSounds { get; set; } + public EAgentStatus? Status { get; set; } + + + public Terrorist() + { + } + + public new const string NameStatic = "Terrorist"; + + public override string Name() => "Terrorist"; + + public override byte[] Serialize() + { + List s = new List(); + + // serialize Id + s.Add((byte)((Id == null) ? 0 : 1)); + if (Id != null) + { + s.AddRange(BitConverter.GetBytes((int)Id)); + } + + // serialize Position + s.Add((byte)((Position == null) ? 0 : 1)); + if (Position != null) + { + s.AddRange(Position.Serialize()); + } + + // serialize PlantingRemainingTime + s.Add((byte)((PlantingRemainingTime == null) ? 0 : 1)); + if (PlantingRemainingTime != null) + { + s.AddRange(BitConverter.GetBytes((int)PlantingRemainingTime)); + } + + // serialize FootstepSounds + s.Add((byte)((FootstepSounds == null) ? 0 : 1)); + if (FootstepSounds != null) + { + List tmp33 = new List(); + tmp33.AddRange(BitConverter.GetBytes((uint)FootstepSounds.Count())); + while (tmp33.Count > 0 && tmp33.Last() == 0) + tmp33.RemoveAt(tmp33.Count - 1); + s.Add((byte)tmp33.Count); + s.AddRange(tmp33); + + foreach (var tmp34 in FootstepSounds) + { + s.Add((byte)((tmp34 == null) ? 0 : 1)); + if (tmp34 != null) + { + s.Add((byte)((sbyte)tmp34)); + } + } + } + + // serialize Status + s.Add((byte)((Status == null) ? 0 : 1)); + if (Status != null) + { + s.Add((byte)((sbyte)Status)); + } + + return s.ToArray(); + } + + public override uint Deserialize(byte[] s, uint offset = 0) + { + // deserialize Id + byte tmp35; + tmp35 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp35 == 1) + { + Id = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + Id = null; + + // deserialize Position + byte tmp36; + tmp36 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp36 == 1) + { + Position = new Position(); + offset = Position.Deserialize(s, offset); + } + else + Position = null; + + // deserialize PlantingRemainingTime + byte tmp37; + tmp37 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp37 == 1) + { + PlantingRemainingTime = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + PlantingRemainingTime = null; + + // deserialize FootstepSounds + byte tmp38; + tmp38 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp38 == 1) + { + byte tmp39; + tmp39 = (byte)s[(int)offset]; + offset += sizeof(byte); + byte[] tmp40 = new byte[sizeof(uint)]; + Array.Copy(s, offset, tmp40, 0, tmp39); + offset += tmp39; + uint tmp41; + tmp41 = BitConverter.ToUInt32(tmp40, (int)0); + + FootstepSounds = new List(); + for (uint tmp42 = 0; tmp42 < tmp41; tmp42++) + { + ESoundIntensity? tmp43; + byte tmp44; + tmp44 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp44 == 1) + { + sbyte tmp45; + tmp45 = (sbyte)s[(int)offset]; + offset += sizeof(sbyte); + tmp43 = (ESoundIntensity)tmp45; + } + else + tmp43 = null; + FootstepSounds.Add(tmp43); + } + } + else + FootstepSounds = null; + + // deserialize Status + byte tmp46; + tmp46 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp46 == 1) + { + sbyte tmp47; + tmp47 = (sbyte)s[(int)offset]; + offset += sizeof(sbyte); + Status = (EAgentStatus)tmp47; + } + else + Status = null; + + return offset; + } + } + + public partial class Police : KSObject + { + public int? Id { get; set; } + public Position Position { get; set; } + public int? DefusionRemainingTime { get; set; } + public List FootstepSounds { get; set; } + public List BombSounds { get; set; } + public EAgentStatus? Status { get; set; } + + + public Police() + { + } + + public new const string NameStatic = "Police"; + + public override string Name() => "Police"; + + public override byte[] Serialize() + { + List s = new List(); + + // serialize Id + s.Add((byte)((Id == null) ? 0 : 1)); + if (Id != null) + { + s.AddRange(BitConverter.GetBytes((int)Id)); + } + + // serialize Position + s.Add((byte)((Position == null) ? 0 : 1)); + if (Position != null) + { + s.AddRange(Position.Serialize()); + } + + // serialize DefusionRemainingTime + s.Add((byte)((DefusionRemainingTime == null) ? 0 : 1)); + if (DefusionRemainingTime != null) + { + s.AddRange(BitConverter.GetBytes((int)DefusionRemainingTime)); + } + + // serialize FootstepSounds + s.Add((byte)((FootstepSounds == null) ? 0 : 1)); + if (FootstepSounds != null) + { + List tmp48 = new List(); + tmp48.AddRange(BitConverter.GetBytes((uint)FootstepSounds.Count())); + while (tmp48.Count > 0 && tmp48.Last() == 0) + tmp48.RemoveAt(tmp48.Count - 1); + s.Add((byte)tmp48.Count); + s.AddRange(tmp48); + + foreach (var tmp49 in FootstepSounds) + { + s.Add((byte)((tmp49 == null) ? 0 : 1)); + if (tmp49 != null) + { + s.Add((byte)((sbyte)tmp49)); + } + } + } + + // serialize BombSounds + s.Add((byte)((BombSounds == null) ? 0 : 1)); + if (BombSounds != null) + { + List tmp50 = new List(); + tmp50.AddRange(BitConverter.GetBytes((uint)BombSounds.Count())); + while (tmp50.Count > 0 && tmp50.Last() == 0) + tmp50.RemoveAt(tmp50.Count - 1); + s.Add((byte)tmp50.Count); + s.AddRange(tmp50); + + foreach (var tmp51 in BombSounds) + { + s.Add((byte)((tmp51 == null) ? 0 : 1)); + if (tmp51 != null) + { + s.Add((byte)((sbyte)tmp51)); + } + } + } + + // serialize Status + s.Add((byte)((Status == null) ? 0 : 1)); + if (Status != null) + { + s.Add((byte)((sbyte)Status)); + } + + return s.ToArray(); + } + + public override uint Deserialize(byte[] s, uint offset = 0) + { + // deserialize Id + byte tmp52; + tmp52 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp52 == 1) + { + Id = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + Id = null; + + // deserialize Position + byte tmp53; + tmp53 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp53 == 1) + { + Position = new Position(); + offset = Position.Deserialize(s, offset); + } + else + Position = null; + + // deserialize DefusionRemainingTime + byte tmp54; + tmp54 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp54 == 1) + { + DefusionRemainingTime = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + DefusionRemainingTime = null; + + // deserialize FootstepSounds + byte tmp55; + tmp55 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp55 == 1) + { + byte tmp56; + tmp56 = (byte)s[(int)offset]; + offset += sizeof(byte); + byte[] tmp57 = new byte[sizeof(uint)]; + Array.Copy(s, offset, tmp57, 0, tmp56); + offset += tmp56; + uint tmp58; + tmp58 = BitConverter.ToUInt32(tmp57, (int)0); + + FootstepSounds = new List(); + for (uint tmp59 = 0; tmp59 < tmp58; tmp59++) + { + ESoundIntensity? tmp60; + byte tmp61; + tmp61 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp61 == 1) + { + sbyte tmp62; + tmp62 = (sbyte)s[(int)offset]; + offset += sizeof(sbyte); + tmp60 = (ESoundIntensity)tmp62; + } + else + tmp60 = null; + FootstepSounds.Add(tmp60); + } + } + else + FootstepSounds = null; + + // deserialize BombSounds + byte tmp63; + tmp63 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp63 == 1) + { + byte tmp64; + tmp64 = (byte)s[(int)offset]; + offset += sizeof(byte); + byte[] tmp65 = new byte[sizeof(uint)]; + Array.Copy(s, offset, tmp65, 0, tmp64); + offset += tmp64; + uint tmp66; + tmp66 = BitConverter.ToUInt32(tmp65, (int)0); + + BombSounds = new List(); + for (uint tmp67 = 0; tmp67 < tmp66; tmp67++) + { + ESoundIntensity? tmp68; + byte tmp69; + tmp69 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp69 == 1) + { + sbyte tmp70; + tmp70 = (sbyte)s[(int)offset]; + offset += sizeof(sbyte); + tmp68 = (ESoundIntensity)tmp70; + } + else + tmp68 = null; + BombSounds.Add(tmp68); + } + } + else + BombSounds = null; + + // deserialize Status + byte tmp71; + tmp71 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp71 == 1) + { + sbyte tmp72; + tmp72 = (sbyte)s[(int)offset]; + offset += sizeof(sbyte); + Status = (EAgentStatus)tmp72; + } + else + Status = null; + + return offset; + } + } + + public partial class World : KSObject + { + public int? Width { get; set; } + public int? Height { get; set; } + public List> Board { get; set; } + public Dictionary Scores { get; set; } + public List Bombs { get; set; } + public List Terrorists { get; set; } + public List Polices { get; set; } + public Constants Constants { get; set; } + + + public World() + { + } + + public new const string NameStatic = "World"; + + public override string Name() => "World"; + + public override byte[] Serialize() + { + List s = new List(); + + // serialize Width + s.Add((byte)((Width == null) ? 0 : 1)); + if (Width != null) + { + s.AddRange(BitConverter.GetBytes((int)Width)); + } + + // serialize Height + s.Add((byte)((Height == null) ? 0 : 1)); + if (Height != null) + { + s.AddRange(BitConverter.GetBytes((int)Height)); + } + + // serialize Board + s.Add((byte)((Board == null) ? 0 : 1)); + if (Board != null) + { + List tmp73 = new List(); + tmp73.AddRange(BitConverter.GetBytes((uint)Board.Count())); + while (tmp73.Count > 0 && tmp73.Last() == 0) + tmp73.RemoveAt(tmp73.Count - 1); + s.Add((byte)tmp73.Count); + s.AddRange(tmp73); + + foreach (var tmp74 in Board) + { + s.Add((byte)((tmp74 == null) ? 0 : 1)); + if (tmp74 != null) + { + List tmp75 = new List(); + tmp75.AddRange(BitConverter.GetBytes((uint)tmp74.Count())); + while (tmp75.Count > 0 && tmp75.Last() == 0) + tmp75.RemoveAt(tmp75.Count - 1); + s.Add((byte)tmp75.Count); + s.AddRange(tmp75); + + foreach (var tmp76 in tmp74) + { + s.Add((byte)((tmp76 == null) ? 0 : 1)); + if (tmp76 != null) + { + s.Add((byte)((sbyte)tmp76)); + } + } + } + } + } + + // serialize Scores + s.Add((byte)((Scores == null) ? 0 : 1)); + if (Scores != null) + { + List tmp77 = new List(); + tmp77.AddRange(BitConverter.GetBytes((uint)Scores.Count())); + while (tmp77.Count > 0 && tmp77.Last() == 0) + tmp77.RemoveAt(tmp77.Count - 1); + s.Add((byte)tmp77.Count); + s.AddRange(tmp77); + + foreach (var tmp78 in Scores) + { + s.Add((byte)((tmp78.Key == null) ? 0 : 1)); + if (tmp78.Key != null) + { + List tmp79 = new List(); + tmp79.AddRange(BitConverter.GetBytes((uint)tmp78.Key.Count())); + while (tmp79.Count > 0 && tmp79.Last() == 0) + tmp79.RemoveAt(tmp79.Count - 1); + s.Add((byte)tmp79.Count); + s.AddRange(tmp79); + + s.AddRange(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(tmp78.Key)); + } + + s.Add((byte)((tmp78.Value == null) ? 0 : 1)); + if (tmp78.Value != null) + { + s.AddRange(BitConverter.GetBytes((float)tmp78.Value)); + } + } + } + + // serialize Bombs + s.Add((byte)((Bombs == null) ? 0 : 1)); + if (Bombs != null) + { + List tmp80 = new List(); + tmp80.AddRange(BitConverter.GetBytes((uint)Bombs.Count())); + while (tmp80.Count > 0 && tmp80.Last() == 0) + tmp80.RemoveAt(tmp80.Count - 1); + s.Add((byte)tmp80.Count); + s.AddRange(tmp80); + + foreach (var tmp81 in Bombs) + { + s.Add((byte)((tmp81 == null) ? 0 : 1)); + if (tmp81 != null) + { + s.AddRange(tmp81.Serialize()); + } + } + } + + // serialize Terrorists + s.Add((byte)((Terrorists == null) ? 0 : 1)); + if (Terrorists != null) + { + List tmp82 = new List(); + tmp82.AddRange(BitConverter.GetBytes((uint)Terrorists.Count())); + while (tmp82.Count > 0 && tmp82.Last() == 0) + tmp82.RemoveAt(tmp82.Count - 1); + s.Add((byte)tmp82.Count); + s.AddRange(tmp82); + + foreach (var tmp83 in Terrorists) + { + s.Add((byte)((tmp83 == null) ? 0 : 1)); + if (tmp83 != null) + { + s.AddRange(tmp83.Serialize()); + } + } + } + + // serialize Polices + s.Add((byte)((Polices == null) ? 0 : 1)); + if (Polices != null) + { + List tmp84 = new List(); + tmp84.AddRange(BitConverter.GetBytes((uint)Polices.Count())); + while (tmp84.Count > 0 && tmp84.Last() == 0) + tmp84.RemoveAt(tmp84.Count - 1); + s.Add((byte)tmp84.Count); + s.AddRange(tmp84); + + foreach (var tmp85 in Polices) + { + s.Add((byte)((tmp85 == null) ? 0 : 1)); + if (tmp85 != null) + { + s.AddRange(tmp85.Serialize()); + } + } + } + + // serialize Constants + s.Add((byte)((Constants == null) ? 0 : 1)); + if (Constants != null) + { + s.AddRange(Constants.Serialize()); + } + + return s.ToArray(); + } + + public override uint Deserialize(byte[] s, uint offset = 0) + { + // deserialize Width + byte tmp86; + tmp86 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp86 == 1) + { + Width = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + Width = null; + + // deserialize Height + byte tmp87; + tmp87 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp87 == 1) + { + Height = BitConverter.ToInt32(s, (int)offset); + offset += sizeof(int); + } + else + Height = null; + + // deserialize Board + byte tmp88; + tmp88 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp88 == 1) + { + byte tmp89; + tmp89 = (byte)s[(int)offset]; + offset += sizeof(byte); + byte[] tmp90 = new byte[sizeof(uint)]; + Array.Copy(s, offset, tmp90, 0, tmp89); + offset += tmp89; + uint tmp91; + tmp91 = BitConverter.ToUInt32(tmp90, (int)0); + + Board = new List>(); + for (uint tmp92 = 0; tmp92 < tmp91; tmp92++) + { + List tmp93; + byte tmp94; + tmp94 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp94 == 1) + { + byte tmp95; + tmp95 = (byte)s[(int)offset]; + offset += sizeof(byte); + byte[] tmp96 = new byte[sizeof(uint)]; + Array.Copy(s, offset, tmp96, 0, tmp95); + offset += tmp95; + uint tmp97; + tmp97 = BitConverter.ToUInt32(tmp96, (int)0); + + tmp93 = new List(); + for (uint tmp98 = 0; tmp98 < tmp97; tmp98++) + { + ECell? tmp99; + byte tmp100; + tmp100 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp100 == 1) + { + sbyte tmp101; + tmp101 = (sbyte)s[(int)offset]; + offset += sizeof(sbyte); + tmp99 = (ECell)tmp101; + } + else + tmp99 = null; + tmp93.Add(tmp99); + } + } + else + tmp93 = null; + Board.Add(tmp93); + } + } + else + Board = null; + + // deserialize Scores + byte tmp102; + tmp102 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp102 == 1) + { + byte tmp103; + tmp103 = (byte)s[(int)offset]; + offset += sizeof(byte); + byte[] tmp104 = new byte[sizeof(uint)]; + Array.Copy(s, offset, tmp104, 0, tmp103); + offset += tmp103; + uint tmp105; + tmp105 = BitConverter.ToUInt32(tmp104, (int)0); + + Scores = new Dictionary(); + for (uint tmp106 = 0; tmp106 < tmp105; tmp106++) + { + string tmp107; + byte tmp109; + tmp109 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp109 == 1) + { + byte tmp110; + tmp110 = (byte)s[(int)offset]; + offset += sizeof(byte); + byte[] tmp111 = new byte[sizeof(uint)]; + Array.Copy(s, offset, tmp111, 0, tmp110); + offset += tmp110; + uint tmp112; + tmp112 = BitConverter.ToUInt32(tmp111, (int)0); + + tmp107 = System.Text.Encoding.GetEncoding("ISO-8859-1").GetString(s.Skip((int)offset).Take((int)tmp112).ToArray()); + offset += tmp112; + } + else + tmp107 = null; + + float? tmp108; + byte tmp113; + tmp113 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp113 == 1) + { + tmp108 = BitConverter.ToSingle(s, (int)offset); + offset += sizeof(float); + } + else + tmp108 = null; + + Scores[tmp107] = tmp108; + } + } + else + Scores = null; + + // deserialize Bombs + byte tmp114; + tmp114 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp114 == 1) + { + byte tmp115; + tmp115 = (byte)s[(int)offset]; + offset += sizeof(byte); + byte[] tmp116 = new byte[sizeof(uint)]; + Array.Copy(s, offset, tmp116, 0, tmp115); + offset += tmp115; + uint tmp117; + tmp117 = BitConverter.ToUInt32(tmp116, (int)0); + + Bombs = new List(); + for (uint tmp118 = 0; tmp118 < tmp117; tmp118++) + { + Bomb tmp119; + byte tmp120; + tmp120 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp120 == 1) + { + tmp119 = new Bomb(); + offset = tmp119.Deserialize(s, offset); + } + else + tmp119 = null; + Bombs.Add(tmp119); + } + } + else + Bombs = null; + + // deserialize Terrorists + byte tmp121; + tmp121 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp121 == 1) + { + byte tmp122; + tmp122 = (byte)s[(int)offset]; + offset += sizeof(byte); + byte[] tmp123 = new byte[sizeof(uint)]; + Array.Copy(s, offset, tmp123, 0, tmp122); + offset += tmp122; + uint tmp124; + tmp124 = BitConverter.ToUInt32(tmp123, (int)0); + + Terrorists = new List(); + for (uint tmp125 = 0; tmp125 < tmp124; tmp125++) + { + Terrorist tmp126; + byte tmp127; + tmp127 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp127 == 1) + { + tmp126 = new Terrorist(); + offset = tmp126.Deserialize(s, offset); + } + else + tmp126 = null; + Terrorists.Add(tmp126); + } + } + else + Terrorists = null; + + // deserialize Polices + byte tmp128; + tmp128 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp128 == 1) + { + byte tmp129; + tmp129 = (byte)s[(int)offset]; + offset += sizeof(byte); + byte[] tmp130 = new byte[sizeof(uint)]; + Array.Copy(s, offset, tmp130, 0, tmp129); + offset += tmp129; + uint tmp131; + tmp131 = BitConverter.ToUInt32(tmp130, (int)0); + + Polices = new List(); + for (uint tmp132 = 0; tmp132 < tmp131; tmp132++) + { + Police tmp133; + byte tmp134; + tmp134 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp134 == 1) + { + tmp133 = new Police(); + offset = tmp133.Deserialize(s, offset); + } + else + tmp133 = null; + Polices.Add(tmp133); + } + } + else + Polices = null; + + // deserialize Constants + byte tmp135; + tmp135 = (byte)s[(int)offset]; + offset += sizeof(byte); + if (tmp135 == 1) + { + Constants = new Constants(); + offset = Constants.Deserialize(s, offset); + } + else + Constants = null; + + return offset; + } + } +} // namespace KS.Models diff --git a/CSharpClient/Game/KS/commands.ks b/CSharpClient/Game/KS/commands.ks new file mode 100644 index 0000000..68f3a41 --- /dev/null +++ b/CSharpClient/Game/KS/commands.ks @@ -0,0 +1,26 @@ +[ECommandDirection] +_def = enum + { + Up, + Right, + Down, + Left + } + + +[Move] +_def = class +id = int +direction = ECommandDirection + + +[PlantBomb] +_def = class +id = int +direction = ECommandDirection + + +[DefuseBomb] +_def = class +id = int +direction = ECommandDirection diff --git a/CSharpClient/Game/KS/models.ks b/CSharpClient/Game/KS/models.ks new file mode 100644 index 0000000..3aad961 --- /dev/null +++ b/CSharpClient/Game/KS/models.ks @@ -0,0 +1,92 @@ +[ECell] +_def = enum + { + Empty, + SmallBombSite, + MediumBombSite, + LargeBombSite, + VastBombSite, + Wall + } + + +[ESoundIntensity] +_def = enum + { + Weak, + Normal, + Strong + } + + +[EAgentStatus] +_def = enum + { + Alive, + Dead + } + + +[Constants] +_def = class +bomb_planting_time = int +bomb_defusion_time = int +bomb_explosion_time = int +bomb_planting_score = int +bomb_defusion_score = int +bomb_explosion_score = int +score_coefficient_small_bomb_site = float +score_coefficient_medium_bomb_site = float +score_coefficient_large_bomb_site = float +score_coefficient_vast_bomb_site = float +terrorist_vision_distance = int +terrorist_death_score = int +police_death_score = int +police_vision_distance = int +sound_ranges = map +max_cycles = int + + +[Position] +_def = class +x = int +y = int + + +[Bomb] +_def = class +position = Position +explosion_remaining_time = int +planter_id = int +defuser_id = int + + +[Terrorist] +_def = class +id = int +position = Position +planting_remaining_time = int +footstep_sounds = list +status = EAgentStatus + + +[Police] +_def = class +id = int +position = Position +defusion_remaining_time = int +footstep_sounds = list +bomb_sounds = list +status = EAgentStatus + + +[World] +_def = class +width = int +height = int +board = list> +scores = map +bombs = list +terrorists = list +polices = list +constants = Constants diff --git a/CSharpClient/Game/Program.cs b/CSharpClient/Game/Program.cs new file mode 100644 index 0000000..6a00d8b --- /dev/null +++ b/CSharpClient/Game/Program.cs @@ -0,0 +1,24 @@ +using System; + +using KoalaTeam.Chillin.Client; +using KS.Models; + +namespace Game +{ + class Program + { + private static readonly string defaultConfigPath = "gamecfg.json"; + + static void Main(string[] args) + { + var configPath = (args.Length > 0) ? args[0] : defaultConfigPath; + + var world = new World(); + AI ai = new AI(world); + + GameClient app = new GameClient(configPath); + app.RegisterAI(ai); + app.Run(); + } + } +} diff --git a/CSharpClient/Game/gamecfg.json b/CSharpClient/Game/gamecfg.json new file mode 100644 index 0000000..cf933e7 --- /dev/null +++ b/CSharpClient/Game/gamecfg.json @@ -0,0 +1,21 @@ +{ + "general": { + "offline_mode": true + }, + + "net": { + "host": "localhost", + "port": 5000, + "max_tries": 5, + "retry_waiting_time": 1, + "timeout": 2 + }, + + "ai": { + "": "creating a new decision thread each time a snapshot of game is received from server", + "create_new_thread": true, + "agent_name": "0", + "team_nickname": "Team1", + "token": "team_id1-xx" + } +}