├── CoreSociety.exe ├── CoreSociety.sln ├── CoreSociety.v11.suo ├── CoreSociety ├── App.config ├── Core.cs ├── CoreSociety.csproj ├── CoreSociety.csproj.user ├── CoreView.cs ├── ExecutionContext.cs ├── Grid.cs ├── GridAuthority.cs ├── Indexer.cs ├── Instruction.cs ├── Listing.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Resources │ ├── Buttons │ │ ├── AddShapeIcon.png │ │ ├── ApplyToCore.png │ │ ├── AutoUpdate.png │ │ ├── AutoUpdateInv.png │ │ ├── ClayModeIcon.png │ │ ├── ClearCore.png │ │ ├── CloneShapeIcon.png │ │ ├── CopyIcon.png │ │ ├── DeleteIcon.png │ │ ├── DeleteShapeIcon.png │ │ ├── Focused.png │ │ ├── GridIcon.png │ │ ├── HelpIcon.png │ │ ├── LoadIcon.png │ │ ├── MissionIcon.png │ │ ├── MoveDownIcon.png │ │ ├── MoveUpIcon.png │ │ ├── NewShapeModeIcon.png │ │ ├── OpenGridIcon.png │ │ ├── OpenIcon.png │ │ ├── PasteIcon.png │ │ ├── PauseIcon.png │ │ ├── PlayIcon.png │ │ ├── RestartIcon.png │ │ ├── Selected.png │ │ ├── StopIcon.png │ │ ├── ToggleGridIcon2.png │ │ ├── Unfocused.png │ │ ├── Unselected.png │ │ └── VertexModeIcon.png │ ├── CSIcon4.ico │ ├── core_frame_basic.png │ ├── core_frame_high.png │ └── core_frame_low.png ├── Scenario.cs └── UI │ ├── AssemblyForm.Designer.cs │ ├── AssemblyForm.cs │ ├── AssemblyForm.resx │ ├── DeckView.Designer.cs │ ├── DeckView.cs │ ├── GridForm.Designer.cs │ ├── GridForm.cs │ ├── GridForm.resx │ ├── GridView.Designer.cs │ └── GridView.cs ├── CoreSocietyTests ├── CoreSocietyTests.csproj ├── IndexerTests.cs ├── Properties │ └── AssemblyInfo.cs └── SerializationTests.cs ├── Documentation.pdf ├── README.md └── Scenarios ├── Demo.xml ├── Mission01.xml ├── Mission02.xml ├── Mission03.xml ├── Mission04.xml ├── Mission05.xml └── Solutions ├── Mission01.xml ├── Mission02.xml ├── Mission03.xml ├── Mission04.xml └── Mission05.xml /CoreSociety.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety.exe -------------------------------------------------------------------------------- /CoreSociety.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreSociety", "CoreSociety\CoreSociety.csproj", "{718C47A5-FD90-44EB-9382-475E8A6171DB}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreSocietyTests", "CoreSocietyTests\CoreSocietyTests.csproj", "{86B379FB-4E9F-4ABF-83DF-A52045897574}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {718C47A5-FD90-44EB-9382-475E8A6171DB} = {718C47A5-FD90-44EB-9382-475E8A6171DB} 9 | EndProjectSection 10 | EndProject 11 | Global 12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 13 | Debug|Any CPU = Debug|Any CPU 14 | Release|Any CPU = Release|Any CPU 15 | EndGlobalSection 16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 17 | {718C47A5-FD90-44EB-9382-475E8A6171DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 18 | {718C47A5-FD90-44EB-9382-475E8A6171DB}.Debug|Any CPU.Build.0 = Debug|Any CPU 19 | {718C47A5-FD90-44EB-9382-475E8A6171DB}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {718C47A5-FD90-44EB-9382-475E8A6171DB}.Release|Any CPU.Build.0 = Release|Any CPU 21 | {86B379FB-4E9F-4ABF-83DF-A52045897574}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {86B379FB-4E9F-4ABF-83DF-A52045897574}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {86B379FB-4E9F-4ABF-83DF-A52045897574}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {86B379FB-4E9F-4ABF-83DF-A52045897574}.Release|Any CPU.Build.0 = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(SolutionProperties) = preSolution 27 | HideSolutionNode = FALSE 28 | EndGlobalSection 29 | EndGlobal 30 | -------------------------------------------------------------------------------- /CoreSociety.v11.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety.v11.suo -------------------------------------------------------------------------------- /CoreSociety/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CoreSociety/Core.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | using CoreSociety.Properties; 9 | 10 | namespace CoreSociety 11 | { 12 | public class Core 13 | { 14 | public enum Focus 15 | { 16 | Up = 0, 17 | Right = 1, 18 | Down = 2, 19 | Left = 3, 20 | Self = 4 21 | } 22 | //MEMORY 23 | public ushort[] Data = new ushort[256]; 24 | public Indexer Memory 25 | { 26 | get { return new Indexer(Data, 16); } 27 | } 28 | //INSTRUCTION POINTER 29 | public byte InstructionPointer = 0; 30 | //FOCUS 31 | public Focus Target = Focus.Self; 32 | //ENERGY 33 | public byte Energy = 0; 34 | public byte Shield = 0; 35 | public byte Charge = 0; 36 | } 37 | 38 | public static class CoreTransform 39 | { 40 | public static void ClearMemory(this Core core) 41 | { 42 | for (short i = 0; i < 256; i++) 43 | core.Memory[i] = 0; 44 | } 45 | 46 | public static IEnumerable GetBytes(this Core core) 47 | { 48 | //data 49 | foreach (ushort word in core.Data) 50 | foreach(byte b in BitConverter.GetBytes(word)) 51 | yield return b; 52 | //ip 53 | yield return core.InstructionPointer; 54 | //focus target 55 | yield return (byte)core.Target; 56 | //energy 57 | yield return core.Energy; 58 | yield return core.Shield; 59 | yield return core.Charge; 60 | } 61 | public static void SetBytes(this Core core, byte[] data) 62 | { 63 | BinaryReader reader = new BinaryReader(new MemoryStream(data)); 64 | //data 65 | for (int i = 0; i < core.Data.Length; i++) 66 | core.Data[i] = reader.ReadUInt16(); 67 | //ip 68 | core.InstructionPointer = reader.ReadByte(); 69 | //focus target 70 | core.Target = (Core.Focus)reader.ReadByte(); 71 | //energy 72 | core.Energy = reader.ReadByte(); 73 | core.Shield = reader.ReadByte(); 74 | core.Charge = reader.ReadByte(); 75 | } 76 | 77 | public static string Encode(this Core core) 78 | { 79 | return System.Convert.ToBase64String(GetBytes(core).ToArray()); 80 | } 81 | 82 | public static void Decode(this Core target, string data) 83 | { 84 | SetBytes(target, System.Convert.FromBase64String(data)); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /CoreSociety/CoreSociety.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {718C47A5-FD90-44EB-9382-475E8A6171DB} 8 | WinExe 9 | Properties 10 | CoreSociety 11 | CoreSociety 12 | v3.5 13 | 512 14 | 15 | 16 | 17 | 18 | AnyCPU 19 | true 20 | full 21 | false 22 | Builds\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | false 27 | true 28 | 29 | 30 | AnyCPU 31 | pdbonly 32 | true 33 | Builds\ 34 | TRACE 35 | prompt 36 | 4 37 | true 38 | false 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Form 63 | 64 | 65 | GridForm.cs 66 | 67 | 68 | UserControl 69 | 70 | 71 | GridView.cs 72 | 73 | 74 | Form 75 | 76 | 77 | AssemblyForm.cs 78 | 79 | 80 | 81 | 82 | UserControl 83 | 84 | 85 | DeckView.cs 86 | 87 | 88 | GridForm.cs 89 | 90 | 91 | AssemblyForm.cs 92 | 93 | 94 | ResXFileCodeGenerator 95 | Resources.Designer.cs 96 | Designer 97 | 98 | 99 | True 100 | Resources.resx 101 | True 102 | 103 | 104 | SettingsSingleFileGenerator 105 | Settings.Designer.cs 106 | 107 | 108 | True 109 | Settings.settings 110 | True 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 172 | -------------------------------------------------------------------------------- /CoreSociety/CoreSociety.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | false 5 | 6 | 7 | false 8 | 9 | -------------------------------------------------------------------------------- /CoreSociety/CoreView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | using CoreSociety.Properties; 8 | 9 | namespace CoreSociety 10 | { 11 | [Flags] 12 | public enum StatusFlags 13 | { 14 | None = 0, 15 | Green = 1, 16 | Yellow = 2, 17 | Red = 4, 18 | Blue = 8, 19 | All = 15 20 | } 21 | 22 | public class CoreView 23 | { 24 | private Bitmap _bitmap; 25 | private Bitmap _highSrc; 26 | private Bitmap _lowSrc; 27 | private Bitmap _baseSrc; 28 | 29 | const int K = 3; 30 | 31 | public int Width 32 | { 33 | get { return _bitmap.Width; } 34 | } 35 | 36 | public int Height 37 | { 38 | get { return _bitmap.Height; } 39 | } 40 | 41 | public Image Image 42 | { 43 | get { return _bitmap; } 44 | } 45 | 46 | public Color BackgroundColor = Color.FromArgb(0, 0, 0); 47 | public Color InstructionFrameColor = Color.FromArgb(120, 100, 160); 48 | 49 | public Color[] Palette = new Color[] 50 | { 51 | Color.FromArgb(34, 26, 55), 52 | 53 | Color.FromArgb(120, 45, 0), 54 | Color.FromArgb(245, 140, 85), 55 | 56 | Color.FromArgb(120, 0, 35), 57 | Color.FromArgb(240, 110, 125), 58 | 59 | Color.FromArgb(70, 15, 95), 60 | Color.FromArgb(168, 100, 168), 61 | 62 | Color.FromArgb(20, 35, 100), 63 | Color.FromArgb(90, 125, 230), 64 | 65 | Color.FromArgb(0, 85, 90), 66 | Color.FromArgb(90, 185, 190), 67 | 68 | Color.FromArgb(5, 95, 0), 69 | Color.FromArgb(124, 198, 118), 70 | 71 | Color.FromArgb(110, 110, 0), 72 | Color.FromArgb(210, 205, 95), 73 | 74 | Color.FromArgb(220, 230, 240), 75 | }; 76 | 77 | public CoreView() 78 | { 79 | _highSrc = Resources.CoreFrameHigh as Bitmap; 80 | _lowSrc = Resources.CoreFrameLow as Bitmap; 81 | _baseSrc = Resources.CoreFrameBasic as Bitmap; 82 | _bitmap = new Bitmap(_lowSrc); 83 | } 84 | 85 | public int PixelToAdress(Point point) 86 | { 87 | point.X -= 5; 88 | point.Y -= 7; 89 | point.X /= K; 90 | point.Y /= K; 91 | if (point.X >= 0 && point.X <= 15 && point.Y >= 0 && point.Y <= 15) 92 | return point.X + point.Y * 16; 93 | else 94 | return -1; 95 | } 96 | 97 | public void RenderBasic(Core core, Color color) 98 | { 99 | //Clear 100 | Graphics gfx = Graphics.FromImage(_bitmap); 101 | gfx.Clear(Color.Transparent); 102 | Rectangle r = new Rectangle(0, 0, _baseSrc.Width, _baseSrc.Height); 103 | Rectangle r2 = r; 104 | r2.Inflate(-2, -2); 105 | gfx.FillRectangle(new SolidBrush(color), r2); 106 | gfx.DrawImage(_baseSrc, r, r, GraphicsUnit.Pixel); 107 | //Render Memory 108 | int i = 0; 109 | for (int y = 0; y < 16; y++) 110 | for (int x = 0; x < 16; x++) 111 | { 112 | int data = core.Memory[i++]; 113 | _bitmap.SetPixel(5 + x * K, y * K + 5, Palette[(data & 0xF000) >> 12]); 114 | _bitmap.SetPixel(6 + x * K, y * K + 5, Palette[(data & 0xF00) >> 8]); 115 | _bitmap.SetPixel(5 + x * K, y * K + 6, Palette[(data & 0xF0) >> 4]); 116 | _bitmap.SetPixel(6 + x * K, y * K + 6, Palette[data & 0xF]); 117 | } 118 | } 119 | 120 | public void Render(Core core, int chargeGoal, StatusFlags status, Color gridColor) 121 | { 122 | //Clear 123 | Graphics gfx = Graphics.FromImage(_bitmap); 124 | gfx.Clear(Color.Transparent); 125 | Rectangle r = new Rectangle(0, 0, _lowSrc.Width, _lowSrc.Height); 126 | Rectangle r2 = r; 127 | r2.Inflate(-2, -2); 128 | gfx.FillRectangle(new SolidBrush(gridColor), r2); 129 | gfx.DrawImage(_lowSrc, r, r, GraphicsUnit.Pixel); 130 | //Render Memory 131 | int i = 0; 132 | for (int y = 0; y < 16; y++) 133 | for (int x = 0; x < 16; x++) 134 | { 135 | int data = core.Memory[i++]; 136 | _bitmap.SetPixel(5 + x * K, y * K + 7, Palette[(data & 0xF000) >> 12]); 137 | _bitmap.SetPixel(6 + x * K, y * K + 7, Palette[(data & 0xF00) >> 8]); 138 | _bitmap.SetPixel(5 + x * K, y * K + 8, Palette[(data & 0xF0) >> 4]); 139 | _bitmap.SetPixel(6 + x * K, y * K + 8, Palette[data & 0xF]); 140 | } 141 | //Render Energy-Levels 142 | RenderVEnergyBar(core.Energy, 0); 143 | RenderVEnergyBar(core.Shield, 52); 144 | RenderHEnergyBar(core.Charge, chargeGoal, 53); 145 | //Render IP 146 | int px = 5 + K * (core.InstructionPointer % 16); 147 | int py = 7 + K * (core.InstructionPointer / 16); 148 | //Color instrColor = Palette[(core.Memory[core.InstructionPointer] & 0xF000) >> 12]; 149 | //Pen pen = new Pen(instrColor); 150 | Pen pen = new Pen(InstructionFrameColor); 151 | gfx.DrawRectangle(pen, new Rectangle(px - 1, py - 1, 3, 3)); 152 | //pen = new Pen(Color.FromArgb(32, Color.White)); 153 | //Graphics.FromImage(_bitmap).DrawRectangle(pen, new Rectangle(px - 2, py - 2, 5, 5)); 154 | RenderStatus(status); 155 | } 156 | 157 | private void RenderStatus(StatusFlags status) 158 | { 159 | if ((status & StatusFlags.Green) > 0) 160 | Blit(new Rectangle(5, 0, 9, 6)); 161 | if ((status & StatusFlags.Yellow) > 0) 162 | Blit(new Rectangle(18, 0, 9, 6)); 163 | if ((status & StatusFlags.Red) > 0) 164 | Blit(new Rectangle(31, 0, 9, 6)); 165 | if ((status & StatusFlags.Blue) > 0) 166 | Blit(new Rectangle(44, 0, 9, 6)); 167 | } 168 | 169 | private void RenderVEnergyBar(int energy, int posX) 170 | { 171 | int barHeight = (energy == 0) ? 0 : 1 + (energy * 51) / 255; 172 | int remainder = energy % 5; 173 | Blit(new Rectangle(posX, 56 - barHeight, posX + 5, barHeight)); 174 | for (int px = posX + 4; px > posX + 4 - remainder; px--) 175 | _bitmap.SetPixel(px, 55 - barHeight, _highSrc.GetPixel(px, 55 - barHeight)); 176 | } 177 | 178 | private void RenderHEnergyBar(int energy, int max, int posY) 179 | { 180 | if (energy == 0) 181 | return; 182 | energy = Math.Min(energy, max); 183 | int remainder = energy % 6; 184 | int offset = (int)(43 * (1 - (max / 255.0f)) * ((float)(energy) / max)); 185 | int barWidth = (energy * 42) / 252; 186 | Blit(new Rectangle(7 + offset, posY, barWidth, posY + 5)); 187 | for (int py = posY + 4; py > posY + 4 - remainder; py--) 188 | _bitmap.SetPixel(7 + offset + barWidth, py, _highSrc.GetPixel(7 + offset + barWidth, py)); 189 | } 190 | 191 | private void Blit(Rectangle rect) 192 | { 193 | Graphics gfx = Graphics.FromImage(_bitmap); 194 | gfx.DrawImage(_highSrc, rect, rect, GraphicsUnit.Pixel); 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /CoreSociety/ExecutionContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | 7 | namespace CoreSociety 8 | { 9 | public class ExecutionContext 10 | { 11 | private Random _rnd = new Random(); 12 | private byte _ip; 13 | private ushort _instr; 14 | private ushort[] _mem = null; 15 | private ushort[] _tgt = null; 16 | private Core _core; 17 | private Core _target; 18 | 19 | public int Score = 0; 20 | 21 | public int InstructionBaseCost = 1; 22 | 23 | public void ConsumeEnergyUntilExecute(Core core, Core target) 24 | { 25 | //spend this energy! 26 | SetContext(core, target); 27 | int cost = GetNextInstructionCost(); 28 | if (core.Energy > 0) 29 | { 30 | int available = core.Energy; 31 | int needed = Math.Max(1, cost - core.Charge); 32 | int spent = Math.Min(needed, available); 33 | core.Charge = (byte)(core.Charge + spent); 34 | core.Energy = (byte)(core.Energy - spent); 35 | } 36 | if (core.Charge >= cost) 37 | { 38 | core.InstructionPointer = Execute(); 39 | core.Charge = 0; 40 | } 41 | } 42 | 43 | public void ConsumeOneEnergy(Core core, Core target) 44 | { 45 | //spend this energy! 46 | SetContext(core, target); 47 | if(core.Energy > 0) 48 | { 49 | core.Charge++; 50 | core.Energy--; 51 | } 52 | if(core.Charge >= GetNextInstructionCost()) 53 | { 54 | core.InstructionPointer = Execute(); 55 | core.Charge = 0; 56 | } 57 | } 58 | 59 | public int GetNextInstructionCost(Core core) 60 | { 61 | _core = core; 62 | _mem = core.Data; 63 | _ip = core.InstructionPointer; 64 | _instr = _mem[_ip]; 65 | return GetNextInstructionCost(); 66 | } 67 | 68 | public void Execute(Core core, Core target) 69 | { 70 | SetContext(core, target); 71 | core.Charge = 0; 72 | core.InstructionPointer = Execute(); 73 | } 74 | 75 | public void ExecuteMultiple(Core core, Core target, int numInstructions) 76 | { 77 | SetContext(core, target); 78 | while (numInstructions-- > 0) 79 | { 80 | _ip = Execute(); 81 | _instr = _mem[_ip]; 82 | } 83 | core.InstructionPointer = _ip; 84 | } 85 | 86 | private void SetContext(Core core, Core target) 87 | { 88 | _core = core; 89 | _target = target; 90 | _mem = core.Data; 91 | _tgt = target.Data; 92 | _ip = core.InstructionPointer; 93 | _instr = _mem[_ip]; 94 | } 95 | 96 | private int GetNextInstructionCost() 97 | { 98 | ushort group = (ushort)(_instr & 0xF000); 99 | if (group == 0xB000 || group == 0xC000) // ENERGY or SCORE GROUP 100 | { 101 | if((_instr & 0xFE00) == (int)Opcode.DSE) 102 | return InstructionBaseCost; //decrease shield energy does not require charging 103 | else 104 | return (byte)Math.Max(InstructionBaseCost, GetTargetValue()); 105 | } 106 | else 107 | return InstructionBaseCost; 108 | } 109 | 110 | private byte GetTargetAddress() 111 | { 112 | byte target = (byte)(_instr & 0xFF); 113 | if ((_instr & Instruction.TARGET_NO_ADDRESS) == Instruction.TARGET_NO_ADDRESS) 114 | target = (byte)(_mem[target] & 0xFF); 115 | 116 | return target; 117 | } 118 | 119 | private ushort GetTargetValue() 120 | { 121 | byte target = (byte)(_instr & 0xFF); 122 | if ((_instr & Instruction.TARGET_NO_ADDRESS) == Instruction.TARGET_NO_ADDRESS) 123 | return target; 124 | else 125 | return _mem[target]; 126 | } 127 | 128 | private byte GetParamAdress() 129 | { 130 | ushort param = _mem[_ip + 1]; 131 | //result.ParamWord |= (ushort)(indir << 8); 132 | byte addr = (byte)param; 133 | int indir = param >> 8; 134 | while (indir-- > 0) 135 | addr = (byte)_mem[addr]; 136 | 137 | return addr; 138 | } 139 | 140 | private ushort GetParamValue() 141 | { 142 | if ((_instr & Instruction.PARAM_NO_NUMERAL) == Instruction.PARAM_NO_NUMERAL) 143 | { 144 | byte target = GetParamAdress(); 145 | return _mem[target]; 146 | } 147 | else 148 | return _mem[_ip + 1]; 149 | } 150 | 151 | private byte Execute() 152 | { 153 | switch (_instr & 0xF000) 154 | { 155 | case 0x1000: 156 | MemOps(); 157 | return (byte)(_ip + 1); 158 | case 0x2000: 159 | CopyOps(); 160 | return (byte)(_ip + 2); 161 | case 0x3000: 162 | case 0x4000: 163 | case 0x5000: 164 | MathOps(); 165 | return (byte)(_ip + 2); 166 | case 0x6000: 167 | if (ConditionalOps()) 168 | return (byte)(_ip + 1); 169 | else 170 | return (byte)(_ip + 2); 171 | case 0x7000: 172 | if (ConditionalParamOps()) 173 | return (byte)(_ip + 2); 174 | else 175 | return (byte)(_ip + 3); 176 | case 0x8000: 177 | if ((_instr & 0xFE00) == (int)Opcode.JMP) 178 | return (byte)(_ip + GetTargetValue()); 179 | if ((_instr & 0xFE00) == (int)Opcode.NXT) 180 | return GetTargetAddress(); 181 | if ((_instr & 0xFE00) == (int)Opcode.SIP && _target.Shield == 0) 182 | _target.InstructionPointer = GetTargetAddress(); 183 | return (byte)(_ip + 1); 184 | case 0x9000: 185 | QueryOps(); 186 | return (byte)(_ip + 1); 187 | case 0xA000: //MODE 188 | ushort val = GetTargetValue(); 189 | if (val < 4) 190 | _core.Target = (Core.Focus)(val); 191 | else 192 | _core.Target = Core.Focus.Self; 193 | return (byte)(_ip + 1); 194 | case 0xB000: 195 | EnergyOps(); 196 | return (byte)(_ip + 1); 197 | case 0xC000: 198 | ScoreOps(); 199 | return (byte)(_ip + 1); 200 | default: 201 | return (byte)(_ip + 1); 202 | } 203 | } 204 | 205 | private void ScoreOps() 206 | { 207 | byte value = (byte)GetTargetValue(); 208 | switch (_instr & 0xFE00) 209 | { 210 | case (int)Opcode.ISC: 211 | Score += value; 212 | break; 213 | case (int)Opcode.DSC: 214 | Score -= value; 215 | if (Score < 0) 216 | Score = 0; 217 | break; 218 | } 219 | } 220 | 221 | private void EnergyOps() 222 | { 223 | byte value = (byte)GetTargetValue(); 224 | switch (_instr & 0xFE00) 225 | { 226 | case (int)Opcode.RSV: 227 | _core.Energy = (byte)Math.Min(255, _core.Energy + value); 228 | break; 229 | case (int)Opcode.ISE: 230 | _core.Shield = (byte)Math.Min(255, _core.Shield + value); 231 | break; 232 | case (int)Opcode.DSE: 233 | _core.Shield = (byte)Math.Max(0, _core.Shield - value); 234 | break; 235 | case (int)Opcode.BST: 236 | _target.Energy = (byte)Math.Min(255, _target.Energy + value); 237 | break; 238 | case (int)Opcode.WKN: 239 | byte maxWeakenValue = Math.Min(value, (byte)15); 240 | byte shieldDmg = (byte)Math.Min(maxWeakenValue, _target.Shield); 241 | byte coreDmg = (byte)(maxWeakenValue - shieldDmg); 242 | _target.Shield = (byte)Math.Max(0, _target.Shield - shieldDmg); 243 | _target.Energy = (byte)Math.Max(0, _target.Energy - coreDmg); 244 | break; 245 | } 246 | } 247 | 248 | private void QueryOps() 249 | { 250 | byte target = GetTargetAddress(); 251 | switch (_instr & 0xFE00) 252 | { 253 | case (int)Opcode.QIP: 254 | _mem[target] = _target.InstructionPointer; 255 | break; 256 | case (int)Opcode.QUE: 257 | _mem[target] = _target.Energy; 258 | break; 259 | case (int)Opcode.QSE: 260 | _mem[target] = _target.Shield; 261 | break; 262 | case (int)Opcode.QCE: 263 | _mem[target] = _target.Charge; 264 | break; 265 | case (int)Opcode.QTC: 266 | _mem[target] = (byte)_target.Target; 267 | break; 268 | } 269 | } 270 | 271 | private bool ConditionalOps() 272 | { 273 | byte target = GetTargetAddress(); 274 | switch (_instr & 0xFE00) 275 | { 276 | case (int)Opcode.IFZ: 277 | return _mem[target] == 0; 278 | case (int)Opcode.IFS: 279 | return _mem[target] != 0; 280 | case (int)Opcode.IFR: 281 | return _mem[target] > (ushort)_rnd.Next(ushort.MaxValue); 282 | } 283 | return false; 284 | } 285 | 286 | private bool ConditionalParamOps() 287 | { 288 | byte target = GetTargetAddress(); 289 | ushort value = GetParamValue(); 290 | switch (_instr & 0xFC00) 291 | { 292 | case (int)Opcode.IFE: 293 | return _mem[target] == value; 294 | case (int)Opcode.IFN: 295 | return _mem[target] != value; 296 | case (int)Opcode.IFG: 297 | return _mem[target] > value; 298 | case (int)Opcode.IFL: 299 | return _mem[target] < value; 300 | } 301 | return false; 302 | } 303 | 304 | private void MathOps() 305 | { 306 | byte target = GetTargetAddress(); 307 | ushort value = GetParamValue(); 308 | switch (_instr & 0xFC00) 309 | { 310 | case (int)Opcode.ADD: 311 | _mem[target] += value; 312 | break; 313 | case (int)Opcode.SUB: 314 | _mem[target] -= value; 315 | break; 316 | case (int)Opcode.MUL: 317 | _mem[target] *= value; 318 | break; 319 | case (int)Opcode.DIV: 320 | _mem[target] /= value; 321 | break; 322 | case (int)Opcode.MOD: 323 | _mem[target] %= value; 324 | break; 325 | case (int)Opcode.MAX: 326 | _mem[target] = Math.Max(_mem[target], value); 327 | break; 328 | case (int)Opcode.MIN: 329 | _mem[target] = Math.Min(_mem[target], value); 330 | break; 331 | case (int)Opcode.AND: 332 | _mem[target] &= value; 333 | break; 334 | case (int)Opcode.IOR: 335 | _mem[target] |= value; 336 | break; 337 | case (int)Opcode.XOR: 338 | _mem[target] ^= value; 339 | break; 340 | } 341 | } 342 | 343 | private void CopyOps() 344 | { 345 | byte target = GetTargetAddress(); 346 | switch (_instr & 0xFC00) 347 | { 348 | case (int)Opcode.SET: 349 | _mem[target] = GetParamValue(); 350 | break; 351 | case (int)Opcode.RDW: 352 | _mem[target] = _tgt[GetParamAdress()]; 353 | break; 354 | case (int)Opcode.STW: 355 | if (_target.Shield == 0) 356 | _tgt[target] = GetParamValue(); 357 | break; 358 | } 359 | } 360 | 361 | private void MemOps() 362 | { 363 | byte target = GetTargetAddress(); 364 | switch (_instr & 0xFE00) 365 | { 366 | case (int)Opcode.INC: 367 | _mem[target]++; 368 | break; 369 | case (int)Opcode.DEC: 370 | _mem[target]--; 371 | break; 372 | case (int)Opcode.NOT: 373 | _mem[target] = (ushort)(~_mem[target]); 374 | break; 375 | case (int)Opcode.RND: 376 | _mem[target] = (ushort)(_rnd.Next(ushort.MaxValue)); 377 | break; 378 | case (int)Opcode.SQT: 379 | _mem[target] = (ushort)Math.Sqrt((double)_mem[target]); 380 | break; 381 | 382 | } 383 | } 384 | } 385 | } 386 | -------------------------------------------------------------------------------- /CoreSociety/Grid.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | 8 | namespace CoreSociety 9 | { 10 | public class Grid 11 | { 12 | public class Entry 13 | { 14 | public Core Core = new Core(); 15 | public Color Color = Color.Black; 16 | public int ListingID = -1; 17 | } 18 | 19 | private List _entries = null; 20 | 21 | private int _width; 22 | public int Width 23 | { 24 | get { return _width; } 25 | } 26 | 27 | private int _height; 28 | public int Height 29 | { 30 | get { return _height; } 31 | } 32 | 33 | public IList ListOfEntries 34 | { 35 | get { return _entries.AsReadOnly(); } 36 | } 37 | 38 | public Indexer Entries 39 | { 40 | get { return new Indexer(_entries, _width); } 41 | } 42 | 43 | public Grid(int width, int height) 44 | { 45 | int count = width * height; 46 | _entries = new List(count); 47 | for (int i = 0; i < count; i++) 48 | _entries.Add(new Entry()); 49 | _width = width; 50 | _height = height; 51 | } 52 | 53 | public Core GetTargetOf(Core core) 54 | { 55 | int x, y; 56 | Indexer c = new Indexer(_entries, _width, ClampMode.Repeat); 57 | c.Find(e => e.Core == core, out x, out y); 58 | switch (core.Target) 59 | { 60 | case Core.Focus.Up: 61 | return c[y - 1, x].Core; 62 | case Core.Focus.Right: 63 | return c[y, x + 1].Core; 64 | case Core.Focus.Down: 65 | return c[y + 1, x].Core; 66 | case Core.Focus.Left: 67 | return c[y, x - 1].Core; 68 | default: 69 | return core; 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /CoreSociety/GridAuthority.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | 7 | namespace CoreSociety 8 | { 9 | public class GridAuthority 10 | { 11 | private int _energy; 12 | public int Energy 13 | { 14 | get { return _energy; } 15 | } 16 | 17 | public int Score 18 | { 19 | get { return _exec.Score; } 20 | } 21 | 22 | private Grid _grid = null; 23 | private ExecutionContext _exec = new ExecutionContext(); 24 | int _nextEnergyReceiver = 0; 25 | HashSet _changeTracker = new HashSet(); 26 | 27 | public delegate void ChangedEventHandler(IEnumerable changedCores); 28 | public event ChangedEventHandler Ticked; 29 | private void NotifyChanges() 30 | { 31 | if (Ticked != null) 32 | Ticked(_changeTracker); 33 | _changeTracker.Clear(); 34 | } 35 | 36 | public void Init(int energy, Grid grid) 37 | { 38 | _grid = grid; 39 | _energy = energy; 40 | _exec.Score = 0; 41 | _nextEnergyReceiver = 0; 42 | _changeTracker.Clear(); 43 | } 44 | 45 | public void Tick(int budget) 46 | { 47 | while (budget > 0 && _energy > 0) 48 | { 49 | Core core = _grid.ListOfEntries.Select(e => e.Core).OrderByDescending(c => c.Energy).First(); 50 | if (core.Energy == 0) 51 | { 52 | core = _grid.Entries[_nextEnergyReceiver++].Core; 53 | budget--; 54 | _energy--; 55 | core.Energy++; 56 | } 57 | Core target = _grid.GetTargetOf(core); 58 | _exec.ConsumeEnergyUntilExecute(core, target); 59 | _changeTracker.Add(core); 60 | _changeTracker.Add(target); 61 | } 62 | NotifyChanges(); 63 | } 64 | 65 | public StatusFlags GetStatusFlags(Core core) 66 | { 67 | 68 | StatusFlags flags = StatusFlags.None; 69 | ushort instr = core.Memory[core.InstructionPointer]; 70 | if ((instr & 0xFE00) == (int)Opcode.ISC) 71 | flags = StatusFlags.Yellow; 72 | else if ((instr & 0xFE00) == (int)Opcode.DSC) 73 | flags = StatusFlags.Yellow; 74 | else if ((instr & 0xFE00) == (int)Opcode.ISE) 75 | flags = StatusFlags.Blue; 76 | else if ((instr & 0xFE00) == (int)Opcode.BST) 77 | flags = StatusFlags.Green; 78 | else if ((instr & 0xFE00) == (int)Opcode.WKN) 79 | flags = StatusFlags.Red; 80 | 81 | return flags; 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /CoreSociety/Indexer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | 7 | namespace CoreSociety 8 | { 9 | public enum ClampMode 10 | { 11 | Repeat, 12 | Clamp, 13 | Wrap 14 | } 15 | 16 | public class Indexer 17 | { 18 | private IList _source; 19 | private int _width = 0; 20 | private int _height = 0; 21 | private ClampMode _adressing = ClampMode.Wrap; 22 | 23 | public Indexer(IList source) 24 | { 25 | _source = source; 26 | _width = source.Count; 27 | _height = 1; 28 | } 29 | 30 | public Indexer(IList source, ClampMode addressing) 31 | { 32 | _source = source; 33 | _width = source.Count; 34 | _height = 1; 35 | _adressing = addressing; 36 | } 37 | 38 | public Indexer(IList source, int stride) 39 | { 40 | _source = source; 41 | _width = stride; 42 | _height = source.Count / _width; 43 | } 44 | 45 | public Indexer(IList source, int stride, ClampMode adressing) 46 | { 47 | _source = source; 48 | _width = stride; 49 | _height = source.Count / _width; 50 | _adressing = adressing; 51 | } 52 | 53 | public bool Contains(int x, int y) 54 | { 55 | return (x >= 0 && x < _width && y >= 0 && y < _height); 56 | } 57 | 58 | private void Localize(ref int x, ref int y, ClampMode mode) 59 | { 60 | switch(mode) 61 | { 62 | case ClampMode.Clamp: 63 | y = Math.Min(_height-1, Math.Max(0, y)); 64 | x = Math.Min(_width-1, Math.Max(0, x)); 65 | return; 66 | case ClampMode.Wrap: 67 | y += x / _width; 68 | x = mod(x, _width); 69 | y = mod(y, _height); 70 | return; 71 | case ClampMode.Repeat: 72 | x = mod(x, _width); 73 | y = mod(y, _height); 74 | return; 75 | } 76 | } 77 | 78 | private int mod(int x, int m) 79 | { 80 | return (x % m + m) % m; //'solve' weirdness of c#'s modulo regarding negative numbers 81 | } 82 | 83 | public T Get(int x, int y, ClampMode mode) 84 | { 85 | Localize(ref x, ref y, mode); 86 | return _source[y * _width + x]; 87 | } 88 | 89 | public void Set(int x, int y, ClampMode mode, T value) 90 | { 91 | Localize(ref x, ref y, mode); 92 | _source[y * _width + x] = value; 93 | } 94 | 95 | public bool Find(Func condition, out int x, out int y) 96 | { 97 | int idx = _source.IndexOf(_source.First(condition)); 98 | if (idx == -1) //indicates value is not in list 99 | { 100 | x = y = -1; 101 | return false; 102 | } 103 | else 104 | { 105 | x = idx % _width; 106 | y = idx / _width; 107 | return true; 108 | } 109 | } 110 | 111 | 112 | public T this[int index] 113 | { 114 | get { return Get(index, 0, _adressing); } 115 | set { Set(index, 0, _adressing, value); } 116 | } 117 | 118 | public T this[int row, int column] 119 | { 120 | get { return Get(column, row, _adressing); } 121 | set { Set(column, row, _adressing, value); } 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /CoreSociety/Instruction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | 7 | namespace CoreSociety 8 | { 9 | public enum Opcode 10 | { 11 | NOP = 0x0000, 12 | //Group 0x1 - Basic Memory Operations 13 | INC = 0x1000, 14 | DEC = 0x1200, 15 | NOT = 0x1400, 16 | RND = 0x1600, 17 | SQT = 0x1800, 18 | //Group 0x2 - Copy 19 | SET = 0x2000, 20 | RDW = 0x2400, 21 | STW = 0x2800, 22 | //Group 0x3 - Basic Arithmetic 23 | ADD = 0x3000, 24 | SUB = 0x3400, 25 | MUL = 0x3800, 26 | DIV = 0x3C00, 27 | //Group 0x4 - Additional Arithmetic 28 | MOD = 0x4000, 29 | MAX = 0x4400, 30 | MIN = 0x4800, 31 | //Group 0x5 - Basic Logical 32 | AND = 0x5000, 33 | IOR = 0x5400, 34 | XOR = 0x5800, 35 | //Group 0x6 - Basic Conditional 36 | IFZ = 0x6000, 37 | IFS = 0x6200, 38 | IFR = 0x6400, 39 | //Group 0x7 - Conditional 40 | IFE = 0x7000, 41 | IFN = 0x7400, 42 | IFG = 0x7800, 43 | IFL = 0x7C00, 44 | //Group 0x8 - Jump & Goto 45 | JMP = 0x8000, 46 | NXT = 0x8200, 47 | SIP = 0x8400, 48 | //Group 0x9 - Query 49 | QIP = 0x9000, 50 | QUE = 0x9200, 51 | QSE = 0x9400, 52 | QCE = 0x9600, 53 | QTC = 0x9800, 54 | //Group 0xA - Modes 55 | TGT = 0xA000, 56 | //Group 0xB - Energy 57 | RSV = 0xB000, 58 | ISE = 0xB200, 59 | DSE = 0xB400, 60 | BST = 0xB600, 61 | WKN = 0xB800, 62 | //GROUP 0xC - Score 63 | ISC = 0xC000, 64 | DSC = 0xC200 65 | } 66 | 67 | public class Instruction 68 | { 69 | public static Dictionary Mnemonics = new Dictionary() 70 | { 71 | {"NOP", Opcode.NOP}, 72 | {"INC", Opcode.INC}, 73 | {"DEC", Opcode.DEC}, 74 | {"NOT", Opcode.NOT}, 75 | {"RND", Opcode.RND}, 76 | {"SQT", Opcode.SQT}, 77 | {"SET", Opcode.SET}, 78 | {"RDW", Opcode.RDW}, 79 | {"STW", Opcode.STW}, 80 | {"ADD", Opcode.ADD}, 81 | {"SUB", Opcode.SUB}, 82 | {"MUL", Opcode.MUL}, 83 | {"DIV", Opcode.DIV}, 84 | {"MOD", Opcode.MOD}, 85 | {"MAX", Opcode.MAX}, 86 | {"MIN", Opcode.MIN}, 87 | {"AND", Opcode.AND}, 88 | {"OR" , Opcode.IOR}, 89 | {"IOR", Opcode.IOR}, 90 | {"XOR", Opcode.XOR}, 91 | {"IFZ", Opcode.IFZ}, 92 | {"IFS", Opcode.IFS}, 93 | {"IFR", Opcode.IFR}, 94 | {"IFE", Opcode.IFE}, 95 | {"IFN", Opcode.IFN}, 96 | {"IFG", Opcode.IFG}, 97 | {"IFL", Opcode.IFL}, 98 | {"JMP", Opcode.JMP}, 99 | {"NXT", Opcode.NXT}, 100 | {"SIP", Opcode.SIP}, 101 | {"QIP", Opcode.QIP}, 102 | {"QUE", Opcode.QUE}, 103 | {"QSE", Opcode.QSE}, 104 | {"QCE", Opcode.QCE}, 105 | {"QTC", Opcode.QTC}, 106 | {"TGT", Opcode.TGT}, 107 | {"RSV", Opcode.RSV}, 108 | {"ISE", Opcode.ISE}, 109 | {"DSE", Opcode.DSE}, 110 | {"BST", Opcode.BST}, 111 | {"WKN", Opcode.WKN}, 112 | {"ISC", Opcode.ISC}, 113 | {"DSC", Opcode.DSC}, 114 | }; 115 | 116 | public static string GetMnemonic(Opcode opcode) 117 | { 118 | return Mnemonics.Where(kvp => kvp.Value == opcode).First().Key; 119 | } 120 | 121 | public static ushort TARGET_NO_ADDRESS = 0x0100; 122 | public static ushort PARAM_NO_NUMERAL = 0x0200; 123 | 124 | public int LineNumber = -1; 125 | public ushort InstructionWord = (ushort)Opcode.NOP; 126 | public ushort ParamWord = 0; 127 | public bool HasParam = false; 128 | public Opcode OpCode = Opcode.NOP; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /CoreSociety/Listing.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace CoreSociety 8 | { 9 | public class Listing 10 | { 11 | public struct IdRange 12 | { 13 | public IdRange(byte min, byte max) 14 | { 15 | Min = min; 16 | Max = max; 17 | } 18 | public byte Min; 19 | public byte Max; 20 | 21 | public bool IsValid 22 | { 23 | get { return Max > Min && Min >= 0; } 24 | } 25 | } 26 | 27 | 28 | public Color Color; 29 | public IdRange Identity; 30 | private Dictionary _labels = new Dictionary(); 31 | private Dictionary _memMap = new Dictionary(); 32 | private List _lines = new List(); 33 | 34 | public delegate void ListingChangedEventHandler(Listing sender); 35 | public event ListingChangedEventHandler Changed; 36 | 37 | public IList Lines 38 | { 39 | get { return _lines.AsReadOnly(); } 40 | } 41 | 42 | public void Parse(IEnumerable lines) 43 | { 44 | _lines = new List(lines); 45 | _labels.Clear(); 46 | _memMap.Clear(); 47 | InternalParse(lines); 48 | _memMap.Clear(); 49 | InternalParse(lines); 50 | if (Changed != null) 51 | Changed(this); 52 | } 53 | 54 | private void InternalParse(IEnumerable lines) 55 | { 56 | byte location = 0; 57 | int lineIndex = -1; 58 | foreach (string line in lines) 59 | { 60 | lineIndex++; 61 | try 62 | { 63 | string ln = line.Trim(); 64 | //skip empty lines 65 | if (ln == "" || ln.StartsWith("/")) 66 | continue; 67 | //location 68 | int b1 = ln.IndexOf('['); 69 | int b2 = ln.IndexOf(']'); 70 | if(b1 > -1 && b2 > b1) 71 | { 72 | string address = ln.Remove(b2).Remove(0, b1+1); 73 | location = ParseByte(address); 74 | continue; 75 | } 76 | //label 77 | string[] split = ln.Split(':'); 78 | if (split.Length == 2) 79 | { 80 | _labels[split[0].ToUpper()] = location; 81 | ln = split[1]; 82 | continue; 83 | } 84 | Instruction instr = ParseInstruction(ln, lineIndex, location); 85 | //special case. Op is JMP and Target is adress. convert it to relative offset 86 | //finish 87 | instr.LineNumber = lineIndex; 88 | _memMap[location++] = instr; 89 | if (instr.HasParam) 90 | location++; 91 | } 92 | catch { }; 93 | } 94 | } 95 | 96 | private Instruction ParseInstruction(string line, int lineIndex, byte location) 97 | { 98 | Instruction i = new Instruction(); 99 | i.LineNumber = lineIndex; 100 | 101 | line = line.Trim(); 102 | string[] tokens = line.Split(' '); 103 | 104 | //DATA 105 | if (tokens.Length == 1) 106 | { 107 | i.InstructionWord = ParseWord(tokens[0].Trim()); 108 | return i; 109 | } 110 | 111 | //INSTRUCTION 112 | string instr = tokens[0].Trim().ToUpper(); 113 | if (Instruction.Mnemonics.ContainsKey(instr)) 114 | { 115 | i.OpCode = Instruction.Mnemonics[instr]; 116 | i.InstructionWord = (ushort)i.OpCode; 117 | } 118 | //TARGET 119 | string tw = tokens[1].Trim().ToUpper(); 120 | char prefix = tw[0]; 121 | if (prefix == '!' || prefix == '~' || prefix == '?') 122 | { 123 | //! = numeral, ~ = indirection 124 | i.InstructionWord |= Instruction.TARGET_NO_ADDRESS; 125 | tw = tw.Remove(0, 1); 126 | } 127 | byte target = ParseByte(tw); 128 | //'?' convert target to local offset 129 | if (prefix == '?') 130 | target = (byte)(target - location); 131 | i.InstructionWord |= target; 132 | 133 | //PARAMETER 134 | if (tokens.Length == 3) 135 | { 136 | i.HasParam = true; 137 | string param = tokens[2].ToUpper(); 138 | if (param[0] == '-') 139 | i.ParamWord = (ushort)(-1 * ParseWord(param.Remove(0, 1))); 140 | else if(param[0] == '!') 141 | i.ParamWord = ParseWord(param.Remove(0, 1)); 142 | else 143 | { 144 | //treat param as address value 145 | i.InstructionWord = (ushort)(i.InstructionWord | Instruction.PARAM_NO_NUMERAL); 146 | byte indir = 0; 147 | while (param[indir] == '~') 148 | indir++; 149 | param = param.Remove(0, indir); 150 | i.ParamWord = (ushort)ParseByte(param); 151 | i.ParamWord |= (ushort)(indir << 8); 152 | } 153 | } 154 | return i; 155 | } 156 | 157 | private byte ParseByte(string value) 158 | { 159 | byte result; 160 | if (!byte.TryParse(value, System.Globalization.NumberStyles.HexNumber, null, out result)) 161 | _labels.TryGetValue(value, out result); 162 | return result; 163 | } 164 | 165 | private ushort ParseWord(string value) 166 | { 167 | ushort result; 168 | if (!ushort.TryParse(value, System.Globalization.NumberStyles.HexNumber, null, out result)) 169 | { 170 | byte addr; 171 | _labels.TryGetValue(value, out addr); 172 | return (ushort)addr; 173 | } 174 | return result; 175 | } 176 | 177 | public Instruction GetInstructionAt(byte location) 178 | { 179 | if (_memMap.ContainsKey(location)) 180 | return _memMap[location]; 181 | else 182 | return null; 183 | } 184 | 185 | public void Compile(Core core) 186 | { 187 | foreach (KeyValuePair kv in _memMap) 188 | { 189 | byte location = kv.Key; 190 | Instruction instr = kv.Value; 191 | core.Memory[location++] = instr.InstructionWord; 192 | if (instr.HasParam) 193 | core.Memory[location++] = instr.ParamWord; 194 | } 195 | } 196 | 197 | public void Unload(Core core) 198 | { 199 | foreach (KeyValuePair kv in _memMap) 200 | { 201 | byte location = kv.Key; 202 | Instruction instr = kv.Value; 203 | core.Memory[location++] = 0; 204 | if (instr.HasParam) 205 | core.Memory[location++] = 0; 206 | } 207 | } 208 | 209 | public bool MatchIdentity(Core core) 210 | { 211 | for (byte location = Identity.Min; location < Identity.Max; location++) 212 | { 213 | if (_memMap.ContainsKey(location)) 214 | { 215 | Instruction instr = _memMap[location]; 216 | if (core.Memory[location] != instr.InstructionWord) 217 | return false; 218 | } 219 | } 220 | return true; 221 | } 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /CoreSociety/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace CoreSociety 7 | { 8 | static class Program 9 | { 10 | /// 11 | /// The main entry point for the application. 12 | /// 13 | [STAThread] 14 | static void Main() 15 | { 16 | Application.EnableVisualStyles(); 17 | Application.SetCompatibleTextRenderingDefault(false); 18 | Application.Run(new UI.GridForm()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CoreSociety/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CoreSociety")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CoreSociety")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0a4fd059-5e29-497d-8bca-eaa3c8b34b3a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /CoreSociety/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.18449 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CoreSociety.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CoreSociety.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Bitmap. 65 | /// 66 | internal static System.Drawing.Bitmap AutoUpdate { 67 | get { 68 | object obj = ResourceManager.GetObject("AutoUpdate", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// Looks up a localized resource of type System.Drawing.Bitmap. 75 | /// 76 | internal static System.Drawing.Bitmap AutoUpdateInv { 77 | get { 78 | object obj = ResourceManager.GetObject("AutoUpdateInv", resourceCulture); 79 | return ((System.Drawing.Bitmap)(obj)); 80 | } 81 | } 82 | 83 | /// 84 | /// Looks up a localized resource of type System.Drawing.Bitmap. 85 | /// 86 | internal static System.Drawing.Bitmap CloneShapeIcon { 87 | get { 88 | object obj = ResourceManager.GetObject("CloneShapeIcon", resourceCulture); 89 | return ((System.Drawing.Bitmap)(obj)); 90 | } 91 | } 92 | 93 | /// 94 | /// Looks up a localized resource of type System.Drawing.Bitmap. 95 | /// 96 | internal static System.Drawing.Bitmap CopyIcon { 97 | get { 98 | object obj = ResourceManager.GetObject("CopyIcon", resourceCulture); 99 | return ((System.Drawing.Bitmap)(obj)); 100 | } 101 | } 102 | 103 | /// 104 | /// Looks up a localized resource of type System.Drawing.Bitmap. 105 | /// 106 | internal static System.Drawing.Bitmap CoreFrameBasic { 107 | get { 108 | object obj = ResourceManager.GetObject("CoreFrameBasic", resourceCulture); 109 | return ((System.Drawing.Bitmap)(obj)); 110 | } 111 | } 112 | 113 | /// 114 | /// Looks up a localized resource of type System.Drawing.Bitmap. 115 | /// 116 | internal static System.Drawing.Bitmap CoreFrameHigh { 117 | get { 118 | object obj = ResourceManager.GetObject("CoreFrameHigh", resourceCulture); 119 | return ((System.Drawing.Bitmap)(obj)); 120 | } 121 | } 122 | 123 | /// 124 | /// Looks up a localized resource of type System.Drawing.Bitmap. 125 | /// 126 | internal static System.Drawing.Bitmap CoreFrameLow { 127 | get { 128 | object obj = ResourceManager.GetObject("CoreFrameLow", resourceCulture); 129 | return ((System.Drawing.Bitmap)(obj)); 130 | } 131 | } 132 | 133 | /// 134 | /// Looks up a localized resource of type System.Drawing.Bitmap. 135 | /// 136 | internal static System.Drawing.Bitmap DeleteIcon { 137 | get { 138 | object obj = ResourceManager.GetObject("DeleteIcon", resourceCulture); 139 | return ((System.Drawing.Bitmap)(obj)); 140 | } 141 | } 142 | 143 | /// 144 | /// Looks up a localized resource of type System.Drawing.Bitmap. 145 | /// 146 | internal static System.Drawing.Bitmap GridIcon { 147 | get { 148 | object obj = ResourceManager.GetObject("GridIcon", resourceCulture); 149 | return ((System.Drawing.Bitmap)(obj)); 150 | } 151 | } 152 | 153 | /// 154 | /// Looks up a localized resource of type System.Drawing.Bitmap. 155 | /// 156 | internal static System.Drawing.Bitmap HelpIcon { 157 | get { 158 | object obj = ResourceManager.GetObject("HelpIcon", resourceCulture); 159 | return ((System.Drawing.Bitmap)(obj)); 160 | } 161 | } 162 | 163 | /// 164 | /// Looks up a localized resource of type System.Drawing.Bitmap. 165 | /// 166 | internal static System.Drawing.Bitmap OpenIcon { 167 | get { 168 | object obj = ResourceManager.GetObject("OpenIcon", resourceCulture); 169 | return ((System.Drawing.Bitmap)(obj)); 170 | } 171 | } 172 | 173 | /// 174 | /// Looks up a localized resource of type System.Drawing.Bitmap. 175 | /// 176 | internal static System.Drawing.Bitmap PasteIcon { 177 | get { 178 | object obj = ResourceManager.GetObject("PasteIcon", resourceCulture); 179 | return ((System.Drawing.Bitmap)(obj)); 180 | } 181 | } 182 | 183 | /// 184 | /// Looks up a localized resource of type System.Drawing.Bitmap. 185 | /// 186 | internal static System.Drawing.Bitmap PauseIcon { 187 | get { 188 | object obj = ResourceManager.GetObject("PauseIcon", resourceCulture); 189 | return ((System.Drawing.Bitmap)(obj)); 190 | } 191 | } 192 | 193 | /// 194 | /// Looks up a localized resource of type System.Drawing.Bitmap. 195 | /// 196 | internal static System.Drawing.Bitmap PlayIcon { 197 | get { 198 | object obj = ResourceManager.GetObject("PlayIcon", resourceCulture); 199 | return ((System.Drawing.Bitmap)(obj)); 200 | } 201 | } 202 | 203 | /// 204 | /// Looks up a localized resource of type System.Drawing.Bitmap. 205 | /// 206 | internal static System.Drawing.Bitmap StopIcon { 207 | get { 208 | object obj = ResourceManager.GetObject("StopIcon", resourceCulture); 209 | return ((System.Drawing.Bitmap)(obj)); 210 | } 211 | } 212 | 213 | /// 214 | /// Looks up a localized resource of type System.Drawing.Bitmap. 215 | /// 216 | internal static System.Drawing.Bitmap Unselected { 217 | get { 218 | object obj = ResourceManager.GetObject("Unselected", resourceCulture); 219 | return ((System.Drawing.Bitmap)(obj)); 220 | } 221 | } 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /CoreSociety/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\Resources\Buttons\OpenIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | 125 | ..\Resources\Buttons\GridIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 126 | 127 | 128 | ..\Resources\Buttons\CloneShapeIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 129 | 130 | 131 | ..\Resources\Buttons\AutoUpdateInv.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 132 | 133 | 134 | ..\Resources\core_frame_basic.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 135 | 136 | 137 | ..\Resources\Buttons\CopyIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 138 | 139 | 140 | ..\Resources\Buttons\PlayIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 141 | 142 | 143 | ..\Resources\Buttons\AutoUpdate.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 144 | 145 | 146 | ..\Resources\Buttons\StopIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 147 | 148 | 149 | ..\Resources\Buttons\Unselected.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 150 | 151 | 152 | ..\Resources\core_frame_high.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 153 | 154 | 155 | ..\Resources\Buttons\DeleteIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 156 | 157 | 158 | ..\Resources\Buttons\PauseIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 159 | 160 | 161 | ..\Resources\Buttons\PasteIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 162 | 163 | 164 | ..\Resources\core_frame_low.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 165 | 166 | 167 | 168 | ..\Resources\Buttons\HelpIcon.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 169 | 170 | -------------------------------------------------------------------------------- /CoreSociety/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.18052 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CoreSociety.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CoreSociety/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/AddShapeIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/AddShapeIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/ApplyToCore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/ApplyToCore.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/AutoUpdate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/AutoUpdate.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/AutoUpdateInv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/AutoUpdateInv.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/ClayModeIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/ClayModeIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/ClearCore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/ClearCore.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/CloneShapeIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/CloneShapeIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/CopyIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/CopyIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/DeleteIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/DeleteIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/DeleteShapeIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/DeleteShapeIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/Focused.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/Focused.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/GridIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/GridIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/HelpIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/HelpIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/LoadIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/LoadIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/MissionIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/MissionIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/MoveDownIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/MoveDownIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/MoveUpIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/MoveUpIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/NewShapeModeIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/NewShapeModeIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/OpenGridIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/OpenGridIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/OpenIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/OpenIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/PasteIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/PasteIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/PauseIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/PauseIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/PlayIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/PlayIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/RestartIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/RestartIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/Selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/Selected.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/StopIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/StopIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/ToggleGridIcon2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/ToggleGridIcon2.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/Unfocused.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/Unfocused.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/Unselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/Unselected.png -------------------------------------------------------------------------------- /CoreSociety/Resources/Buttons/VertexModeIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/Buttons/VertexModeIcon.png -------------------------------------------------------------------------------- /CoreSociety/Resources/CSIcon4.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/CSIcon4.ico -------------------------------------------------------------------------------- /CoreSociety/Resources/core_frame_basic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/core_frame_basic.png -------------------------------------------------------------------------------- /CoreSociety/Resources/core_frame_high.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/core_frame_high.png -------------------------------------------------------------------------------- /CoreSociety/Resources/core_frame_low.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/CoreSociety/Resources/core_frame_low.png -------------------------------------------------------------------------------- /CoreSociety/Scenario.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Xml.Linq; 7 | 8 | namespace CoreSociety 9 | { 10 | class Scenario 11 | { 12 | XDocument _xml = null; 13 | 14 | public Scenario(XDocument xdoc) 15 | { 16 | _xml = xdoc; 17 | } 18 | 19 | public string MissionStatement 20 | { 21 | get 22 | { 23 | 24 | XElement ms = _xml.Descendants("mission").FirstOrDefault(); 25 | return ms != null ? ms.Value : "No Mission Statement provided!"; 26 | } 27 | } 28 | 29 | public int Width 30 | { 31 | get { return _xml.Descendants("grid").Attributes("width").Select(attr => int.Parse(attr.Value)).FirstOrDefault(); } 32 | } 33 | 34 | public int Height 35 | { 36 | get { return _xml.Descendants("grid").Attributes("height").Select(attr => int.Parse(attr.Value)).FirstOrDefault(); } 37 | } 38 | 39 | public int EnergyBudget 40 | { 41 | get { return _xml.Descendants("budget").Select(node => int.Parse(node.Value)).FirstOrDefault(); } 42 | } 43 | 44 | public IEnumerable Deck 45 | { 46 | get 47 | { 48 | return CreateDeck(); 49 | } 50 | } 51 | 52 | public Grid Grid 53 | { 54 | get 55 | { 56 | return CreateGrid(); 57 | } 58 | } 59 | 60 | public void Save(string filePath) 61 | { 62 | _xml.Save(filePath); 63 | } 64 | 65 | public static Scenario Load(string filePath) 66 | { 67 | return new Scenario(XDocument.Load(filePath)); 68 | } 69 | 70 | private IEnumerable CreateDeck() 71 | { 72 | foreach (XElement node in _xml.Descendants("deck").Descendants("listing")) 73 | { 74 | Listing listing = new Listing(); 75 | string[] lines = node.Value 76 | .Split(new string[] { "\n" }, StringSplitOptions.None) 77 | .Select(line => line.Trim()) 78 | .ToArray(); 79 | listing.Parse(lines); 80 | if (node.Attribute("color") != null) 81 | listing.Color = ColorFromHex(node.Attribute("color").Value); 82 | 83 | if (node.Attribute("idrange") != null) 84 | { 85 | string[] range = node.Attribute("idrange").Value.Split('-'); 86 | listing.Identity = new Listing.IdRange(ByteFromHex(range[0]), ByteFromHex(range[1])); 87 | } 88 | 89 | yield return listing; 90 | } 91 | } 92 | 93 | private CoreSociety.Grid CreateGrid() 94 | { 95 | Grid grid = new Grid(Width, Height); 96 | int i = 0; 97 | foreach (XElement node in _xml.Descendants("grid").Descendants("core")) 98 | { 99 | Grid.Entry entry = grid.ListOfEntries[i++]; 100 | if (node.Value != "") 101 | entry.Core.Decode(node.Value); 102 | if (node.Attribute("color") != null) 103 | entry.Color = ColorFromHex(node.Attribute("color").Value); 104 | if (node.Attribute("listing") != null) 105 | entry.ListingID = int.Parse(node.Attribute("listing").Value); 106 | } 107 | return grid; 108 | } 109 | 110 | /* 111 | * STATIC 112 | */ 113 | 114 | public static Scenario Create(Grid grid, int budget, IEnumerable listings, string mission, bool writeCoreState) 115 | { 116 | XDocument xdoc = new XDocument( 117 | new XElement("scenario", 118 | new XElement("mission", new XText(mission)), 119 | new XElement("budget", new XText(budget.ToString())), 120 | new XElement("deck"), 121 | new XElement("grid", new XAttribute("width", grid.Width.ToString()), new XAttribute("height", grid.Height.ToString())) 122 | ) 123 | ); 124 | XElement deckNode = xdoc.Descendants("deck").First(); 125 | foreach (Listing listing in listings) 126 | { 127 | XElement listingNode = new XElement("listing"); 128 | listingNode.Value = listing.Lines.Aggregate((agg, token) => agg + "\n" + token); 129 | listingNode.SetAttributeValue("color", ColorToHex(listing.Color)); 130 | if(listing.Identity.IsValid) 131 | { 132 | string range = ByteToHex(listing.Identity.Min)+"-"+ByteToHex(listing.Identity.Max); 133 | listingNode.SetAttributeValue("idrange", range); 134 | } 135 | deckNode.Add(listingNode); 136 | } 137 | 138 | XElement gridNode = xdoc.Descendants("grid").First(); 139 | foreach (Grid.Entry entry in grid.ListOfEntries) 140 | { 141 | XElement coreNode = new XElement("core"); 142 | if (writeCoreState) 143 | coreNode.Value = entry.Core.Encode(); 144 | coreNode.SetAttributeValue("listing", entry.ListingID); 145 | coreNode.SetAttributeValue("color", ColorToHex(entry.Color)); 146 | gridNode.Add(coreNode); 147 | } 148 | return new Scenario(xdoc); 149 | } 150 | 151 | public static byte ByteFromHex(string hex) 152 | { 153 | return byte.Parse(hex, System.Globalization.NumberStyles.HexNumber); 154 | } 155 | 156 | public static string ByteToHex(byte value) 157 | { 158 | return value.ToString("X2"); 159 | } 160 | 161 | public static Color ColorFromHex(string hexNotation) 162 | { 163 | uint color = uint.Parse(hexNotation, System.Globalization.NumberStyles.HexNumber); 164 | byte red = (byte)((0xFF0000 & color) >> 16); 165 | byte green = (byte)((0xFF00 & color) >> 8); 166 | byte blue = (byte)(0xFF & color); 167 | return Color.FromArgb(red, green, blue); 168 | } 169 | 170 | public static string ColorToHex(Color color) 171 | { 172 | string result = ""; 173 | result += color.R.ToString("X2"); 174 | result += color.G.ToString("X2"); 175 | result += color.B.ToString("X2"); 176 | return result; 177 | } 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /CoreSociety/UI/AssemblyForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Drawing.Drawing2D; 7 | using System.Drawing.Imaging; 8 | using System.IO; 9 | using System.Linq; 10 | using System.Text; 11 | 12 | using System.Windows.Forms; 13 | using CoreSociety.Properties; 14 | 15 | namespace CoreSociety.UI 16 | { 17 | public partial class AssemblyForm : Form 18 | { 19 | public AssemblyForm() 20 | { 21 | InitializeComponent(); 22 | Setup(); 23 | UpdateView(); 24 | } 25 | const int MAIN_CORE_SCALE = 4; 26 | 27 | private bool _autoUpdate = true; 28 | private Grid _grid = new Grid(2, 2); 29 | private Grid.Entry _focus = null; 30 | private int _focusAddress = -1; 31 | 32 | 33 | public Core SelectedCore 34 | { 35 | get { return _focus.Core; } 36 | } 37 | 38 | public Core SelectedCoreTarget 39 | { 40 | get { return _grid.GetTargetOf(SelectedCore); } 41 | } 42 | 43 | public void Select(Grid.Entry entry) 44 | { 45 | if (_focus != null) 46 | _focus.Color = Color.Black; 47 | _focus = entry; 48 | _focus.Color = Color.DarkSlateBlue; 49 | UpdateView(); 50 | } 51 | 52 | private ExecutionContext _interpreter = new ExecutionContext(); 53 | private Listing _listing = new Listing(); 54 | private CoreView _coreView = new CoreView(); 55 | private Bitmap _upscaledCoreBmp; 56 | private Graphics _upscaledCoreGfx = null; 57 | 58 | private int _batchSize = 1; 59 | 60 | public Listing Listing 61 | { 62 | get { return _listing; } 63 | set { SetListing(value); } 64 | } 65 | 66 | private void SetListing(Listing listing) 67 | { 68 | if(_listing != null) 69 | _listing.Unload(SelectedCore); 70 | 71 | _listing = listing; 72 | listingBox.SelectionBackColor = Color.FromArgb(34, 26, 55); 73 | listingBox.Lines = listing.Lines.ToArray(); 74 | _listing.Parse(listingBox.Lines); 75 | _listing.Compile(SelectedCore); 76 | UpdateView(false); 77 | } 78 | 79 | private void Setup() 80 | { 81 | gridView.Data = _grid; 82 | //Grid & Focus 83 | _focus = _grid.Entries[0]; 84 | _focus.Color = Color.DarkSlateBlue; 85 | //Rendering 86 | int w = _coreView.Width * MAIN_CORE_SCALE; 87 | int h = _coreView.Height * MAIN_CORE_SCALE; 88 | _upscaledCoreBmp = new Bitmap(w, h); 89 | _upscaledCoreGfx = Graphics.FromImage(_upscaledCoreBmp); 90 | _upscaledCoreGfx.PixelOffsetMode = PixelOffsetMode.Half; 91 | _upscaledCoreGfx.InterpolationMode = InterpolationMode.NearestNeighbor; 92 | //Target List 93 | coreTarget.Items.AddRange(Enum.GetNames(typeof(Core.Focus))); 94 | coreTarget.SelectedIndex = (int)Core.Focus.Self; 95 | } 96 | 97 | private void OnListingChanged(object sender, EventArgs e) 98 | { 99 | if (_autoUpdate) 100 | { 101 | ParseListing(); 102 | UpdateView(false); 103 | } 104 | } 105 | 106 | private void UpdateView(bool updateFocusWord = true) 107 | { 108 | numIP.Value = SelectedCore.InstructionPointer; 109 | unboundEnergy.Value = SelectedCore.Energy; 110 | shieldEnergy.Value = SelectedCore.Shield; 111 | chargedEnergy.Value = SelectedCore.Charge; 112 | coreTarget.SelectedIndex = Math.Min((int)SelectedCore.Target, 5); 113 | UpdateMemBox(); 114 | RenderCores(); 115 | if(updateFocusWord) 116 | SetFocusWord(SelectedCore.InstructionPointer); 117 | } 118 | 119 | private void RenderFocusCore() 120 | { 121 | //Focus Core 122 | _coreView.Render(_focus.Core, _interpreter.GetNextInstructionCost(_focus.Core), StatusFlags.Blue, Color.Black); 123 | _upscaledCoreGfx.DrawImage(_coreView.Image, 0, 0, _coreView.Width * MAIN_CORE_SCALE, _coreView.Height * MAIN_CORE_SCALE); 124 | } 125 | 126 | private void RenderCores() 127 | { 128 | gridView.RebuildBuffer(); 129 | RenderFocusCore(); 130 | coreRenderView.Image = _upscaledCoreBmp; 131 | } 132 | 133 | private void ParseListing() 134 | { 135 | _listing.Unload(SelectedCore); 136 | _listing.Parse(listingBox.Lines); 137 | _listing.Compile(SelectedCore); 138 | } 139 | 140 | private void ExecuteNext() 141 | { 142 | if (cbEnergy.Checked) 143 | _interpreter.ConsumeOneEnergy(SelectedCore, SelectedCoreTarget); 144 | else 145 | _interpreter.Execute(SelectedCore, SelectedCoreTarget); 146 | UpdateView(); 147 | } 148 | 149 | private void ExecuteBatch(int i) 150 | { 151 | if (cbEnergy.Checked) 152 | { 153 | while (SelectedCore.Energy > 0 && i-- > 0) 154 | _interpreter.ConsumeEnergyUntilExecute(SelectedCore, SelectedCoreTarget); 155 | } 156 | else 157 | _interpreter.ExecuteMultiple(SelectedCore, SelectedCoreTarget, i); 158 | 159 | UpdateView(); 160 | } 161 | 162 | private void stepBtn_Click(object sender, EventArgs e) 163 | { 164 | ExecuteNext(); 165 | } 166 | 167 | private void runClock_Tick(object sender, EventArgs e) 168 | { 169 | ExecuteBatch(_batchSize); 170 | } 171 | 172 | private void OnRunSpeedChanged(object sender, EventArgs e) 173 | { 174 | UpdateAutoRun(); 175 | } 176 | 177 | private void UpdateAutoRun() 178 | { 179 | int speedVal = autoRunSpeed.Value; 180 | int batchVal = batchSize.Value; 181 | 182 | if (speedVal == 0 || !cbAutoStep.Checked) 183 | runClock.Enabled = false; 184 | else 185 | { 186 | runClock.Interval = 1000 / speedVal; 187 | runClock.Enabled = true; 188 | } 189 | _batchSize = (batchVal > 0) ? (int)Math.Pow(2, (batchSize.Value - 1)) : 0; 190 | txtAutoRun.Text = autoRunSpeed.Value + " X " + _batchSize.ToString(); 191 | } 192 | 193 | private void OnBatchSizeChanged(object sender, EventArgs e) 194 | { 195 | UpdateAutoRun(); 196 | } 197 | 198 | private void OnIpValueChanged(object sender, EventArgs e) 199 | { 200 | SelectedCore.InstructionPointer = (byte)numIP.Value; 201 | UpdateView(); 202 | } 203 | 204 | private void OnUnboundEnergyChanged(object sender, EventArgs e) 205 | { 206 | SelectedCore.Energy = (byte)unboundEnergy.Value; 207 | RenderCores(); 208 | } 209 | 210 | private void OnShieldEnergyChanged(object sender, EventArgs e) 211 | { 212 | SelectedCore.Shield = (byte)shieldEnergy.Value; 213 | RenderCores(); 214 | } 215 | 216 | private void OnChargeLevelChanged(object sender, EventArgs e) 217 | { 218 | SelectedCore.Charge = (byte)chargedEnergy.Value; 219 | RenderCores(); 220 | } 221 | 222 | private void OnCoreFocusTargetChanged(object sender, EventArgs e) 223 | { 224 | SelectedCore.Target = (Core.Focus)coreTarget.SelectedIndex; 225 | } 226 | 227 | private void OnCoreRenderViewClick(object sender, MouseEventArgs e) 228 | { 229 | int addr = _coreView.PixelToAdress(ImageToFocusCore(e.Location)); 230 | if (addr >= 0) 231 | numIP.Value = addr; 232 | } 233 | 234 | private Point ImageToFocusCore(Point pt) 235 | { 236 | pt.X /= MAIN_CORE_SCALE; 237 | pt.Y /= MAIN_CORE_SCALE; 238 | return pt; 239 | } 240 | 241 | private void OnRenderViewMouseMove(object sender, MouseEventArgs e) 242 | { 243 | int addr = _coreView.PixelToAdress(ImageToFocusCore(e.Location)); 244 | if (addr >= 0) 245 | SetFocusWord(addr); 246 | else 247 | SetFocusWord(SelectedCore.InstructionPointer); 248 | } 249 | 250 | private void SetFocusWord(int addr) 251 | { 252 | Instruction instr = _listing.GetInstructionAt((byte)addr); 253 | if (_focusAddress != addr) 254 | { 255 | _focusAddress = addr; 256 | if (instr != null) 257 | { 258 | 259 | txtOpCode.Text = Instruction.GetMnemonic(instr.OpCode); 260 | txtAddress.Text = addr.ToString("X2"); 261 | } 262 | else 263 | { 264 | txtAddress.Text = "--"; 265 | txtOpCode.Text = "---"; 266 | } 267 | SelectListingLine(instr); 268 | SelectMemoryBlock(addr); 269 | } 270 | } 271 | 272 | private void SelectListingLine(Instruction instr) 273 | { 274 | int lines = listingBox.Lines.Count(); 275 | //the select magic can't deal with the listingBox having the focus currently 276 | txtOpCode.Focus(); 277 | //also prevent triggering auto updating temporarily 278 | bool oldAutoUpdate = _autoUpdate; 279 | _autoUpdate = false; 280 | //..finally: the magic 281 | listingBox.SuspendLayout(); 282 | listingBox.SelectAll(); 283 | listingBox.SelectionBackColor = Color.FromArgb(34, 26, 55); 284 | if (instr != null && instr.LineNumber < lines) 285 | { 286 | listingBox.Select(listingBox.GetFirstCharIndexFromLine(instr.LineNumber), listingBox.Lines[instr.LineNumber].Length); 287 | listingBox.SelectionBackColor = Color.SlateBlue; 288 | } 289 | listingBox.ResumeLayout(); 290 | //restore 291 | _autoUpdate = oldAutoUpdate; 292 | } 293 | 294 | private void btnToggleAutoUpdate_Click(object sender, EventArgs e) 295 | { 296 | _autoUpdate = btnToggleAutoUpdate.Checked; 297 | btnToggleAutoUpdate.Image = _autoUpdate ? (Image)Resources.AutoUpdateInv : (Image)Resources.AutoUpdate; 298 | } 299 | 300 | private void btnClearListing_Click(object sender, EventArgs e) 301 | { 302 | listingBox.Text = ""; 303 | } 304 | 305 | private void btnLoadListing_Click(object sender, EventArgs e) 306 | { 307 | OpenFileDialog dlg = new OpenFileDialog(); 308 | if(dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) 309 | { 310 | StreamReader reader = new StreamReader(dlg.OpenFile()); 311 | listingBox.Text = reader.ReadToEnd(); 312 | reader.Close(); 313 | } 314 | } 315 | 316 | private void btnSaveListing_Click(object sender, EventArgs e) 317 | { 318 | SaveFileDialog dlg = new SaveFileDialog(); 319 | if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) 320 | { 321 | StreamWriter writer = new StreamWriter(dlg.OpenFile()); 322 | writer.Write(listingBox.Text); 323 | writer.Close(); 324 | } 325 | } 326 | 327 | private void btnAssemble_Click(object sender, EventArgs e) 328 | { 329 | ParseListing(); 330 | UpdateView(); 331 | } 332 | 333 | private void btnClear_Click(object sender, EventArgs e) 334 | { 335 | SelectedCore.ClearMemory(); 336 | UpdateView(); 337 | } 338 | 339 | private void OnAutoStepCheckedChanged(object sender, EventArgs e) 340 | { 341 | UpdateAutoRun(); 342 | } 343 | 344 | private void copyToolStripMenuItem_Click(object sender, EventArgs e) 345 | { 346 | Core core = coreContextMenu.Tag as Core; 347 | if (core != null) 348 | Clipboard.SetText(core.Encode()); 349 | } 350 | 351 | private void pasteToolStripMenuItem_Click(object sender, EventArgs e) 352 | { 353 | Core core = coreContextMenu.Tag as Core; 354 | if (core != null) 355 | { 356 | try 357 | { 358 | core.Decode(Clipboard.GetText()); 359 | } 360 | catch (Exception ex) 361 | { 362 | MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 363 | } 364 | } 365 | UpdateView(); 366 | } 367 | 368 | private void btnGrid_Click(object sender, EventArgs e) 369 | { 370 | GridForm gridForm = new GridForm(); 371 | gridForm.Show(); 372 | } 373 | 374 | private void memoryBox_KeyPress(object sender, KeyPressEventArgs e) 375 | { 376 | e.Handled = true; 377 | char c = e.KeyChar; 378 | if (IsHex(c)) 379 | { 380 | memoryBox.SuspendLayout(); 381 | memoryBox.SelectionBackColor = Color.FromArgb(34, 26, 55); 382 | int idx = memoryBox.SelectionStart; 383 | string txt = memoryBox.Text; 384 | while(idx < txt.Length && !IsHex(txt[idx])) 385 | idx++; 386 | txt = txt.Remove(idx, 1); 387 | txt = txt.Insert(idx, c.ToString().ToUpper()); 388 | memoryBox.Text = txt; 389 | memoryBox.SelectionStart = idx + 1; 390 | memoryBox.ResumeLayout(); 391 | ParseMemBox(); 392 | RenderCores(); 393 | } 394 | } 395 | 396 | private static bool IsHex(char c) 397 | { 398 | bool isHex = (c >= '0' && c <= '9') || 399 | (c >= 'a' && c <= 'f') || 400 | (c >= 'A' && c <= 'F'); 401 | return isHex; 402 | } 403 | 404 | private void UpdateMemBox() 405 | { 406 | string text = ""; 407 | for (short y = 0; y < 16; y++) 408 | { 409 | string line = ""; 410 | for (short x = 0; x < 16; x++) 411 | line += String.Format("{0:X4} ", SelectedCore.Memory[y, x]); 412 | if (y < 15) 413 | line += '\n'; 414 | text += line; 415 | } 416 | memoryBox.SelectionBackColor = Color.FromArgb(34, 26, 55); 417 | memoryBox.Text = text; 418 | } 419 | 420 | private void SelectMemoryBlock(int address) 421 | { 422 | int lines = memoryBox.Lines.Count(); 423 | memoryBox.SelectAll(); 424 | memoryBox.SelectionBackColor = Color.FromArgb(34, 26, 55); 425 | memoryBox.Select(address * 5 + address / lines, 4); 426 | memoryBox.SelectionBackColor = Color.SlateBlue; 427 | memoryBox.ResumeLayout(); 428 | } 429 | 430 | private void ParseMemBox() 431 | { 432 | string text = memoryBox.Text; 433 | int i = 0; 434 | foreach (string token in text.Split(' ')) 435 | { 436 | if (token.Length < 4) 437 | continue; 438 | string word = token; 439 | if(word[0] == '\n') 440 | word = token.Remove(0,1); 441 | ushort num = ushort.Parse(word, System.Globalization.NumberStyles.HexNumber); 442 | SelectedCore.Memory[i++] = num; 443 | } 444 | } 445 | 446 | private void gridView_MouseClick(object sender, MouseEventArgs e) 447 | { 448 | Grid.Entry entry = gridView.Pick(e.Location); 449 | if (e.Button == MouseButtons.Left && entry != null && _focus != entry) 450 | { 451 | Select(entry); 452 | return; 453 | } 454 | if (e.Button == MouseButtons.Right) 455 | { 456 | //show context menu! 457 | coreContextMenu.Tag = entry.Core; 458 | coreContextMenu.Show(gridView.PointToScreen(e.Location)); 459 | } 460 | } 461 | 462 | 463 | 464 | } 465 | } 466 | -------------------------------------------------------------------------------- /CoreSociety/UI/AssemblyForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 117, 17 125 | 126 | 127 | 128 | 129 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 130 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABNSURBVDhP7YzBCgAgDEL3/z9d7CBYqV079EA2nLMEIyhy 131 | C8a7MtPD4aUwY3MwOODUYC5IU2Bz3O52ngcqoPZf8HRB08dUEJ8BgkobVRNUPFqmNlC9wgAAAABJRU5E 132 | rkJggg== 133 | 134 | 135 | 136 | 137 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 138 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABxSURBVDhPrYwBCsAwDALz/09vCBPUpaWBHhRqzqRu8Qxe 139 | y1I0tN3JAfDrTw8A2+kOYKbz7BwfoMuO5ZSAy3TZsZwScJkuO5ZTAi7TZcdySsBluuxYTgm4TJcdy53U 140 | B/QP9O/hgwv6FMur4ulsy6ZY9QJ251OtK2hznAAAAABJRU5ErkJggg== 141 | 142 | 143 | 144 | 145 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 146 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABySURBVDhPrYwBCsAwDALz/09vCBPUpesCPQg0PU2d4hpM 147 | y1I0tNnJAfDKTw8A63wdWLlfB/DPSbYHtMxRbO+kDtA30LcvDyzQZcb2lIBluszYnhKwTJcZ21MCluky 148 | Y3tKwDJdZmzXMIW+Qf6ra9kGqqpuWM1QsMEyUuIAAAAASUVORK5CYII= 149 | 150 | 151 | 152 | 153 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 154 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABeSURBVDhPnYwBCsAwDAL7/09vJCAoFXQ7EO1Bc4jnY4RL 155 | FMgfPHA9ZUAv8iixB6abDOjFybTZWZk2O5FNBvTiZNrsrEybncgmA3pxMm12VqbNTmSTAb3Io+Q68CPn 156 | vD2sf4FnzkMRAAAAAElFTkSuQmCC 157 | 158 | 159 | 160 | 161 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 162 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABuSURBVDhPnYwBDsAgCAP9/6c3SlIDUifukqZQKyPwXCpR 163 | ggbpDxdePwnQnbQ0kQfgHQG6I8MNrQPwVDBUZ6JCzDFfO3RHhgZ2isiuCjFTEdUtIVzNIOaTNUyPBvbP 164 | jgw3HA90BOhOWpqUAz80xgsfBneJb/vySAAAAABJRU5ErkJggg== 165 | 166 | 167 | 168 | 169 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 170 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABnSURBVDhPpYoBDgAhCMP8/6c94cRMmARjkymstEF/DC1v 171 | QstTKOzwJvtCQM/yP5MgAe8sChMYJLhQABWXHtifZV8muKNniQXAXOhOwkegM5aC7VkvrBmFFo7MKXhQ 172 | jbBmFNUI42/9A6RUyDhdrYVpAAAAAElFTkSuQmCC 173 | 174 | 175 | 176 | 177 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 178 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABcSURBVDhPlYkBCgBBCAL7/6fvEJJkIcyB0MZqvufA1U0R 179 | IscBqZ1p3Tp0WsdHiR2KHri6KULkOCC1M61bh07r+CixQ9EDVzdFiBwHpHamdevQaR0fJXYoeuDgqn5i 180 | TIN9VDHmdAAAAABJRU5ErkJggg== 181 | 182 | 183 | 184 | 17, 56 185 | 186 | 187 | 188 | AAABAAEAICAAAAEACACoCAAAFgAAACgAAAAgAAAAQAAAAAEACAAAAAAAgAQAABMLAAATCwAAAAEAAAAA 189 | AAAAAAAA////AFZLawBeNkIAnXWAAFQxOgAcAwkARRwlABAHCQByQ04AvpWeADgSGgAIAwQAWSo0AFAm 190 | LwBsOUMAek1WAIhXYQDlu8QALwUNAEkQGgBVGiUAWiEsAGUnMgBfKzUAaDA6AP7j6ABgJS8APsLxAA2F 191 | 6wApVJYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 192 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 193 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 194 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 195 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 196 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 197 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 198 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 199 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 200 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 201 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 202 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 203 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 204 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 205 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 206 | AAAAAAAA//////////////////////////////////////////////////////////////////////// 207 | //////////////////////////////8MDAj/////////////////////////////////////CA0KBwj/ 208 | /////////////////////////////////wgQARoFCP//////////////////////////////////DBIB 209 | CgcI//////////////////////////////8MCP8IEgESC////wgI////////////////////////DAwF 210 | AAYSAQoLCP8IEwsM/////////////////////wgHEhIABhIBCg0LBhMJCQ4GCP////////////////// 211 | CxIBCgALChoaEgQHCQ0NCQ8LDP////////////8MCAgHEgEKExMEAQESDxUPGA0NCQkOBv////////// 212 | DAwFEwcSGgQG/wgQChUUFxAXDQ0NGAkDCwwACP///wwMBBoNDhIaBBMGCAYUFRYPEREXFw0NDQkRCw4L 213 | CP//CBEBGgcJEhoSBBUVGRUbEBEVFRERFxgNDQMOCRAG//8IEgESBw8KAQEEFhsVGREVFRcbFRARFw0N 214 | DQcFEAb//wgSARIDABkSBBQVGxARFRcXFxcXFRURCRcOBwUQBv//CBIBEhgTABQUFQ8RCRUYGwcVGxcX 215 | GxUQEAkHBRAG//8IEgEaChgVFRYQERUbBR4dHR4OFxcXGxUVEQwHEBP//wAKARoRFBUZEQkVGR4dHR0d 216 | HR4YFxcWFAwMAxIKBv//CAgEDxMbEBEVFQMdHBwcHR0dHhgXFgwMDAQSBAz/////DBMHDxEVFRcXEBwc 217 | HBwdHR0DFxYMGAz/DAsI//////8IDhAQFRcXFxcJHBwcHBwdAhYUABERDP///////////wgRERUbFxcX 218 | FxcJBBwcHhkWFAwSAQQM////////////DA4QEBUVGxcXFxcXGBcVFAAMBwoKDP//////////////DBMN 219 | EBAVFhsXFxcXFRQRDP//DAz//////////////////wwTDRAQFRUbGxUUGhoM//////////////////// 220 | //////8MExYJEBYVDAoKFgz/////////////////////////////CBMOFAD/CwgM//////////////// 221 | /////////////////wgI//////////////////////////////////////////////////////////// 222 | //////////////////////////////////////////////////////////////////////////////// 223 | //////////////////////////j////wf///4H///+B///8g5//+AEP//AAA//wAAH/gAAA/wBAAA4AA 224 | AAGAAAABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAADwAAAR8AAAH/AAAB/wAAA/+AAGf/4AB///gAf//+C 225 | P///5/////////////////// 226 | 227 | 228 | -------------------------------------------------------------------------------- /CoreSociety/UI/DeckView.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace CoreSociety.UI 2 | { 3 | partial class DeckView 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | components = new System.ComponentModel.Container(); 32 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 33 | } 34 | 35 | #endregion 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /CoreSociety/UI/DeckView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Drawing; 5 | using System.Data; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | 10 | namespace CoreSociety.UI 11 | { 12 | public partial class DeckView : UserControl 13 | { 14 | public DeckView() 15 | { 16 | this.DoubleBuffered = true; 17 | InitializeComponent(); 18 | RebuildBuffer(); 19 | } 20 | 21 | private List _data = null; 22 | public List Data 23 | { 24 | get { return _data; } 25 | set 26 | { 27 | Unsubscribe(_data); 28 | _data = value; 29 | Subscribe(_data); 30 | RebuildBuffer(); 31 | } 32 | } 33 | 34 | private void Unsubscribe(List listings) 35 | { 36 | if (listings != null) 37 | foreach (Listing ls in listings) 38 | ls.Changed -= OnListingChanged; 39 | } 40 | 41 | private void Subscribe(List listings) 42 | { 43 | if(listings != null) 44 | foreach(Listing ls in listings) 45 | ls.Changed += OnListingChanged; 46 | } 47 | 48 | void OnListingChanged(Listing sender) 49 | { 50 | Render(sender); 51 | } 52 | 53 | private Core _core = new Core(); 54 | private CoreView _coreView = new CoreView(); 55 | private Bitmap _buffer = null; 56 | 57 | private int _coreMargin = 3; 58 | public int CoreMargin 59 | { 60 | get { return _coreMargin; } 61 | set { _coreMargin = value; RebuildBuffer(); } 62 | } 63 | 64 | private void ResetOffset() 65 | { 66 | if (_buffer != null) 67 | { 68 | _offset = (Width - _buffer.Width) / 2; 69 | } 70 | } 71 | 72 | private int _offset = 0; 73 | 74 | public int OffsetX 75 | { 76 | get { return _offset; } 77 | set { _offset = value; Invalidate(); } 78 | } 79 | 80 | public void RebuildBuffer() 81 | { 82 | _buffer = null; 83 | if (_data != null) 84 | { 85 | int bufferWidth = _data.Count * (_coreView.Width + _coreMargin); 86 | int bufferHeight = _coreView.Height; 87 | _buffer = new Bitmap(bufferWidth, bufferHeight); 88 | 89 | Graphics gfx = Graphics.FromImage(_buffer); 90 | int i = 0; 91 | foreach(Listing listing in _data) 92 | { 93 | _core.ClearMemory(); 94 | listing.Compile(_core); 95 | _coreView.RenderBasic(_core, listing.Color); 96 | gfx.DrawImage(_coreView.Image, i++ * (_coreView.Width + _coreMargin), 0); 97 | } 98 | } 99 | Invalidate(); 100 | } 101 | 102 | public void Render(Listing listing) 103 | { 104 | if (_data != null && _buffer != null) 105 | { 106 | Graphics gfx = Graphics.FromImage(_buffer); 107 | int i = _data.IndexOf(listing); 108 | _core.ClearMemory(); 109 | listing.Compile(_core); 110 | _coreView.RenderBasic(_core, listing.Color); 111 | gfx.DrawImage(_coreView.Image, i * (_coreView.Width + _coreMargin), 0); 112 | } 113 | Invalidate(); 114 | } 115 | 116 | protected override void OnResize(EventArgs e) 117 | { 118 | base.OnResize(e); 119 | Invalidate(); 120 | } 121 | 122 | protected override void OnPaint(PaintEventArgs e) 123 | { 124 | base.OnPaint(e); 125 | if (_buffer != null) 126 | { 127 | Graphics gfx = e.Graphics; 128 | gfx.DrawImage(_buffer, _offset, 0); 129 | } 130 | } 131 | 132 | public Listing Pick(Point pixel) 133 | { 134 | if (_data == null) 135 | return null; 136 | 137 | int index = pixel.X / (_coreView.Width + _coreMargin); 138 | if (index < _data.Count) 139 | return _data[index]; 140 | else 141 | return null; 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /CoreSociety/UI/GridForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | using System.Windows.Forms; 11 | using System.Xml; 12 | using CoreSociety.Properties; 13 | 14 | namespace CoreSociety.UI 15 | { 16 | public partial class GridForm : Form 17 | { 18 | private bool _playing = false; 19 | private bool _started = false; 20 | private bool _loaded = false; 21 | private int _energyPerTick = 1; 22 | 23 | private Scenario _scenario = null; 24 | private Grid _grid = null; 25 | private List _deck = null; 26 | private GridAuthority _ga = null; 27 | private SaveFileDialog _saveFileDlg = new SaveFileDialog(); 28 | private OpenFileDialog _openFileDlg = new OpenFileDialog(); 29 | 30 | List _assembyForms = new List(); 31 | private bool _isScrolling = false; 32 | private Point _scrollPos = new Point(); 33 | 34 | public GridForm() 35 | { 36 | InitializeComponent(); 37 | batchSize.Value = 8; 38 | UpdateButtonStates(); 39 | 40 | _ga = new GridAuthority(); 41 | _ga.Ticked += OnCoresChanged; 42 | _saveFileDlg.DefaultExt = "xml"; 43 | _saveFileDlg.FileName = "NewScenario"; 44 | } 45 | 46 | private void btnLoad_Click(object sender, EventArgs e) 47 | { 48 | if (_openFileDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) 49 | { 50 | string path = _openFileDlg.FileName; 51 | this.Text = "Core Grid - " + Path.GetFileNameWithoutExtension(path); 52 | _scenario = Scenario.Load(path); 53 | LoadScenario(_scenario, true); 54 | DisplayMissionStatement(); 55 | _loaded = true; 56 | } 57 | } 58 | 59 | private void btnSave_Click(object sender, EventArgs e) 60 | { 61 | if (_saveFileDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) 62 | { 63 | _scenario = Scenario.Create(_grid, _ga.Energy, _deck, _scenario.MissionStatement, false); 64 | _scenario.Save(_saveFileDlg.FileName); 65 | } 66 | } 67 | 68 | private void btnStop_Click(object sender, EventArgs e) 69 | { 70 | _started = false; 71 | _playing = false; 72 | LoadScenario(_scenario, false); 73 | UpdateButtonStates(); 74 | } 75 | 76 | private void btnStartPause_Click(object sender, EventArgs e) 77 | { 78 | _started = true; 79 | _playing = !_playing; 80 | UpdateButtonStates(); 81 | } 82 | 83 | private void btnMission_Click(object sender, EventArgs e) 84 | { 85 | DisplayMissionStatement(); 86 | } 87 | 88 | private void LoadScenario(Scenario scenario, bool loadListings) 89 | { 90 | _grid = scenario.Grid; 91 | _ga.Init(scenario.EnergyBudget, _grid); 92 | gridView.Data = _grid; 93 | if (loadListings) 94 | { 95 | _deck = _scenario.Deck.ToList(); 96 | deckView.Data = _deck; 97 | UpdateContextMenu(); 98 | } 99 | foreach (Grid.Entry entry in _grid.ListOfEntries.Where(entry => entry.ListingID >= 0 && entry.ListingID < _deck.Count)) 100 | { 101 | entry.Core.ClearMemory(); 102 | _deck[entry.ListingID].Compile(entry.Core); 103 | Draw(entry.Core); 104 | } 105 | _loaded = true; 106 | UpdateView(); 107 | } 108 | 109 | private void DisplayMissionStatement() 110 | { 111 | if (_scenario != null) 112 | MessageBox.Show(_scenario.MissionStatement, "Mission", MessageBoxButtons.OK, MessageBoxIcon.Information); 113 | } 114 | 115 | private void UpdateContextMenu() 116 | { 117 | ToolStripMenuItem deckEntry = gridContextMenu.Items["deckToolStripMenuItem"] as ToolStripMenuItem; 118 | deckEntry.DropDownItems.Clear(); 119 | int i = 0; 120 | foreach(Listing listing in _deck) 121 | { 122 | ToolStripMenuItem slotEntry = new ToolStripMenuItem("Slot " + i++, null, deckSlotPaste_Click); 123 | slotEntry.ForeColor = listing.Color; 124 | slotEntry.Tag = listing; 125 | deckEntry.DropDownItems.Add(slotEntry); 126 | }; 127 | } 128 | 129 | private void deckSlotPaste_Click(object sender, EventArgs e) 130 | { 131 | ToolStripMenuItem slotEntry = sender as ToolStripMenuItem; 132 | Core core = gridContextMenu.Tag as Core; 133 | Listing listing = slotEntry.Tag as Listing; 134 | if (core == null || listing == null) 135 | return; 136 | 137 | int index = _deck.IndexOf(listing); 138 | 139 | Grid.Entry coreEntry = _grid.ListOfEntries.Where(entry => entry.Core == core).FirstOrDefault(); 140 | coreEntry.ListingID = index; 141 | coreEntry.Color = listing.Color; 142 | 143 | core.ClearMemory(); 144 | listing.Compile(core); 145 | Draw(core); 146 | 147 | //update scenario 148 | _scenario = Scenario.Create(_grid, _ga.Energy, _deck, _scenario.MissionStatement, true); 149 | } 150 | 151 | private void UpdateView() 152 | { 153 | UpdateButtonStates(); 154 | txtEnergy.Text = _ga.Energy.ToString(); 155 | txtScore.Text = _ga.Score.ToString(); 156 | } 157 | 158 | private void OnCoresChanged(IEnumerable cores) 159 | { 160 | foreach(Core core in cores) 161 | Draw(core); 162 | 163 | UpdateView(); 164 | } 165 | 166 | private void UpdateButtonStates() 167 | { 168 | btnLoad.Enabled = !_started; 169 | btnSave.Enabled = _loaded && !_started; 170 | btnStartPause.Enabled = _loaded; 171 | btnMission.Enabled = _loaded; 172 | btnStartPause.Image = _playing ? (Image)Resources.PauseIcon : (Image)Resources.PlayIcon; 173 | btnStop.Enabled = _started; 174 | } 175 | 176 | private void gridView_MouseMove(object sender, MouseEventArgs e) 177 | { 178 | if (_isScrolling) 179 | { 180 | gridView.OffsetX += e.Location.X - _scrollPos.X; 181 | gridView.OffsetY += e.Location.Y - _scrollPos.Y; 182 | _scrollPos = e.Location; 183 | } 184 | } 185 | 186 | private void gridView_MouseLeave(object sender, EventArgs e) 187 | { 188 | _isScrolling = false; 189 | } 190 | 191 | private void gridView_MouseDown(object sender, MouseEventArgs e) 192 | { 193 | _scrollPos = e.Location; 194 | if (e.Button == System.Windows.Forms.MouseButtons.Left) 195 | _isScrolling = true; 196 | } 197 | 198 | private void gridView_MouseUp(object sender, MouseEventArgs e) 199 | { 200 | _isScrolling = false; 201 | } 202 | 203 | private void gridView_MouseClick(object sender, MouseEventArgs e) 204 | { 205 | if (e.Button == System.Windows.Forms.MouseButtons.Right && _loaded) 206 | { 207 | Grid.Entry entry = gridView.Pick(e.Location); 208 | if (entry != null) 209 | { 210 | //show context menu! 211 | gridContextMenu.Tag = entry.Core; 212 | gridContextMenu.Show(gridView.PointToScreen(e.Location)); 213 | } 214 | } 215 | } 216 | 217 | private void copyToolStripMenuItem_Click(object sender, EventArgs e) 218 | { 219 | Core core = gridContextMenu.Tag as Core; 220 | if (core != null) 221 | Clipboard.SetText(core.Encode()); 222 | } 223 | 224 | 225 | private void pasteToolStripMenuItem_Click(object sender, EventArgs e) 226 | { 227 | Core core = gridContextMenu.Tag as Core; 228 | if (core != null) 229 | { 230 | try 231 | { 232 | core.Decode(Clipboard.GetText()); 233 | Draw(core); 234 | } 235 | catch (Exception ex) 236 | { 237 | MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 238 | } 239 | } 240 | } 241 | 242 | private void Draw(Core core) 243 | { 244 | foreach(Listing listing in _deck.Where(l => l.Identity.IsValid)) 245 | if(listing.MatchIdentity(core)) 246 | { 247 | Grid.Entry coreEntry = _grid.ListOfEntries.Where(entry => entry.Core == core).FirstOrDefault(); 248 | coreEntry.Color = listing.Color; 249 | } 250 | gridView.Render(core, _ga.GetStatusFlags(core)); 251 | } 252 | 253 | private void resetToolStripMenuItem_Click(object sender, EventArgs e) 254 | { 255 | Core core = gridContextMenu.Tag as Core; 256 | if (core != null) 257 | { 258 | Grid.Entry coreEntry = _grid.ListOfEntries.Where(entry => entry.Core == core).FirstOrDefault(); 259 | coreEntry.ListingID = -1; 260 | coreEntry.Color = Color.Black; 261 | core.ClearMemory(); 262 | Draw(core); 263 | } 264 | } 265 | 266 | private void autoRunSpeed_ValueChanged(object sender, EventArgs e) 267 | { 268 | int speedVal = autoRunSpeed.Value; 269 | txtTicksPerSecond.Text = "T:"+autoRunSpeed.Value; 270 | runClock.Interval = 1000 / speedVal; 271 | } 272 | 273 | 274 | private void batchSize_ValueChanged(object sender, EventArgs e) 275 | { 276 | int batchVal = batchSize.Value; 277 | _energyPerTick = (batchVal > 0) ? (int)Math.Pow(2, (batchSize.Value - 1)) : 0; 278 | txtEnergyPerTick.Text = "E:" + _energyPerTick; 279 | } 280 | 281 | private void runClock_Tick(object sender, EventArgs e) 282 | { 283 | if (_loaded && _playing) 284 | _ga.Tick(_energyPerTick); 285 | } 286 | 287 | private void deckView_MouseClick(object sender, MouseEventArgs e) 288 | { 289 | Listing listing = deckView.Pick(e.Location); 290 | if (listing != null) 291 | { 292 | if (e.Button == System.Windows.Forms.MouseButtons.Left) 293 | { 294 | AssemblyForm assembly = _assembyForms.FirstOrDefault(af => af.Listing == listing); 295 | if (assembly == null) 296 | { 297 | listing.Changed += OnListingChanged; 298 | assembly = new AssemblyForm(); 299 | assembly.Listing = listing; 300 | assembly.FormClosing += OnAssemblyClosing; 301 | _assembyForms.Add(assembly); 302 | assembly.Show(); 303 | } 304 | else 305 | assembly.BringToFront(); 306 | } 307 | }; 308 | } 309 | 310 | private void OnListingChanged(Listing sender) 311 | { 312 | if(_started) 313 | return; 314 | 315 | int index = _deck.IndexOf(sender); 316 | foreach (Core core in _grid.ListOfEntries.Where(e => e.ListingID == index).Select(e => e.Core)) 317 | { 318 | core.ClearMemory(); 319 | sender.Compile(core); 320 | Draw(core); 321 | } 322 | } 323 | 324 | private void OnAssemblyClosing(object sender, FormClosingEventArgs e) 325 | { 326 | AssemblyForm form = sender as AssemblyForm; 327 | form.FormClosing -= OnAssemblyClosing; 328 | _assembyForms.Remove(form as AssemblyForm); 329 | } 330 | } 331 | } 332 | -------------------------------------------------------------------------------- /CoreSociety/UI/GridForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 125 | 126 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 127 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABxSURBVDhPrYwBCsAwDALz/09vCBPUpaWBHhRqzqRu8Qxe 128 | y1I0tN3JAfDrTw8A2+kOYKbz7BwfoMuO5ZSAy3TZsZwScJkuO5ZTAi7TZcdySsBluuxYTgm4TJcdy53U 129 | B/QP9O/hgwv6FMur4ulsy6ZY9QJ251OtK2hznAAAAABJRU5ErkJggg== 130 | 131 | 132 | 133 | 134 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 135 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABySURBVDhPrYwBCsAwDALz/09vCBPUpesCPQg0PU2d4hpM 136 | y1I0tNnJAfDKTw8A63wdWLlfB/DPSbYHtMxRbO+kDtA30LcvDyzQZcb2lIBluszYnhKwTJcZ21MCluky 137 | Y3tKwDJdZmzXMIW+Qf6ra9kGqqpuWM1QsMEyUuIAAAAASUVORK5CYII= 138 | 139 | 140 | 141 | 142 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 143 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABsSURBVDhPnY1RCsAwCMV6/0tv+JGSWhm6wINHNXYlniIj 144 | KmF0hOX8e/tIPjA+Uh2w6F7CgmUC7hcMLTrgfsDAUg64b3i0kAPuGx4tOOB+wMASAfcLhhYtuJew8EsO 145 | 8gFoyUG12JYDfnY+WOsFoahbpWymo0sAAAAASUVORK5CYII= 146 | 147 | 148 | 149 | 150 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 151 | YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABZSURBVDhPrczbCoBQEELR+f+fLnzYYpxKuiwQYYSZP20v 152 | crAcissHfL+L0JZDi9CWQ4vQlkOL0JZDi9CWQ4vQlkOL0JZDi9CWQ4vQlkOL0LYcitMHT/PVzA5wEYt1 153 | fOZaRAAAAABJRU5ErkJggg== 154 | 155 | 156 | 157 | 145, 17 158 | 159 | 160 | 292, 17 161 | 162 | 163 | 164 | AAABAAEAICAAAAEACACoCAAAFgAAACgAAAAgAAAAQAAAAAEACAAAAAAAgAQAABMLAAATCwAAAAEAAAAA 165 | AAAAAAAA////AFZLawBeNkIAnXWAAFQxOgAcAwkARRwlABAHCQByQ04AvpWeADgSGgAIAwQAWSo0AFAm 166 | LwBsOUMAek1WAIhXYQDlu8QALwUNAEkQGgBVGiUAWiEsAGUnMgBfKzUAaDA6AP7j6ABgJS8APsLxAA2F 167 | 6wApVJYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 168 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 169 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 170 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 171 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 172 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 173 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 174 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 175 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 176 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 177 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 178 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 179 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 180 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 181 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 182 | AAAAAAAA//////////////////////////////////////////////////////////////////////// 183 | //////////////////////////////8MDAj/////////////////////////////////////CA0KBwj/ 184 | /////////////////////////////////wgQARoFCP//////////////////////////////////DBIB 185 | CgcI//////////////////////////////8MCP8IEgESC////wgI////////////////////////DAwF 186 | AAYSAQoLCP8IEwsM/////////////////////wgHEhIABhIBCg0LBhMJCQ4GCP////////////////// 187 | CxIBCgALChoaEgQHCQ0NCQ8LDP////////////8MCAgHEgEKExMEAQESDxUPGA0NCQkOBv////////// 188 | DAwFEwcSGgQG/wgQChUUFxAXDQ0NGAkDCwwACP///wwMBBoNDhIaBBMGCAYUFRYPEREXFw0NDQkRCw4L 189 | CP//CBEBGgcJEhoSBBUVGRUbEBEVFRERFxgNDQMOCRAG//8IEgESBw8KAQEEFhsVGREVFRcbFRARFw0N 190 | DQcFEAb//wgSARIDABkSBBQVGxARFRcXFxcXFRURCRcOBwUQBv//CBIBEhgTABQUFQ8RCRUYGwcVGxcX 191 | GxUQEAkHBRAG//8IEgEaChgVFRYQERUbBR4dHR4OFxcXGxUVEQwHEBP//wAKARoRFBUZEQkVGR4dHR0d 192 | HR4YFxcWFAwMAxIKBv//CAgEDxMbEBEVFQMdHBwcHR0dHhgXFgwMDAQSBAz/////DBMHDxEVFRcXEBwc 193 | HBwdHR0DFxYMGAz/DAsI//////8IDhAQFRcXFxcJHBwcHBwdAhYUABERDP///////////wgRERUbFxcX 194 | FxcJBBwcHhkWFAwSAQQM////////////DA4QEBUVGxcXFxcXGBcVFAAMBwoKDP//////////////DBMN 195 | EBAVFhsXFxcXFRQRDP//DAz//////////////////wwTDRAQFRUbGxUUGhoM//////////////////// 196 | //////8MExYJEBYVDAoKFgz/////////////////////////////CBMOFAD/CwgM//////////////// 197 | /////////////////wgI//////////////////////////////////////////////////////////// 198 | //////////////////////////////////////////////////////////////////////////////// 199 | //////////////////////////j////wf///4H///+B///8g5//+AEP//AAA//wAAH/gAAA/wBAAA4AA 200 | AAGAAAABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAADwAAAR8AAAH/AAAB/wAAA/+AAGf/4AB///gAf//+C 201 | P///5/////////////////// 202 | 203 | 204 | -------------------------------------------------------------------------------- /CoreSociety/UI/GridView.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace CoreSociety.UI 2 | { 3 | partial class GridView 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | components = new System.ComponentModel.Container(); 32 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 33 | } 34 | 35 | #endregion 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /CoreSociety/UI/GridView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Drawing; 5 | using System.Data; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | using System.Windows.Forms; 10 | 11 | namespace CoreSociety.UI 12 | { 13 | public partial class GridView : UserControl 14 | { 15 | public GridView() 16 | { 17 | this.DoubleBuffered = true; 18 | InitializeComponent(); 19 | RebuildBuffer(); 20 | } 21 | 22 | private CoreView _coreView = new CoreView(); 23 | private ExecutionContext _interpreter = new ExecutionContext(); 24 | private Bitmap _buffer = null; 25 | 26 | private int _coreMargin = 3; 27 | public int CoreMargin 28 | { 29 | get { return _coreMargin; } 30 | set { _coreMargin = value; RebuildBuffer(); } 31 | } 32 | 33 | private Grid _data = null; 34 | public Grid Data 35 | { 36 | get { return _data; } 37 | set { _data = value; RebuildBuffer(); ResetOffset(); } 38 | } 39 | 40 | private void ResetOffset() 41 | { 42 | if (_buffer != null) 43 | { 44 | _offset.X = (Width - _buffer.Width) / 2; 45 | _offset.Y = (Height - _buffer.Height) / 2; 46 | } 47 | } 48 | 49 | private Point _offset = new Point(); 50 | 51 | public int OffsetX 52 | { 53 | get { return _offset.X; } 54 | set { _offset.X = value; Invalidate(); } 55 | } 56 | 57 | public int OffsetY 58 | { 59 | get { return _offset.Y; } 60 | set { _offset.Y = value; Invalidate(); } 61 | } 62 | 63 | public void RebuildBuffer() 64 | { 65 | _buffer = null; 66 | if (_data != null) 67 | { 68 | int bufferWidth = _data.Width * (_coreView.Width + _coreMargin); 69 | int bufferHeight = _data.Height * (_coreView.Height + _coreMargin); 70 | _buffer = new Bitmap(bufferWidth, bufferHeight); 71 | 72 | Graphics gfx = Graphics.FromImage(_buffer); 73 | for (int y = 0; y < _data.Height; y++) 74 | for (int x = 0; x < _data.Width; x++) 75 | { 76 | Grid.Entry entry = _data.Entries[y, x]; 77 | _coreView.Render(entry.Core, _interpreter.GetNextInstructionCost(entry.Core), StatusFlags.None, entry.Color); 78 | gfx.DrawImage(_coreView.Image, x * (_coreView.Width + _coreMargin), y * (_coreView.Height + _coreMargin)); 79 | } 80 | } 81 | Invalidate(); 82 | } 83 | 84 | public void Render(Core core, StatusFlags statusFlags) 85 | { 86 | if (_data != null && _buffer != null) 87 | { 88 | Graphics gfx = Graphics.FromImage(_buffer); 89 | int x, y; 90 | if(_data.Entries.Find(e => e.Core == core, out x, out y)) 91 | { 92 | _coreView.Render(core, _interpreter.GetNextInstructionCost(core), statusFlags, _data.Entries[y, x].Color); 93 | gfx.DrawImage(_coreView.Image, x * (_coreView.Width + _coreMargin), y * (_coreView.Height + _coreMargin)); 94 | } 95 | } 96 | Invalidate(); 97 | } 98 | 99 | protected override void OnResize(EventArgs e) 100 | { 101 | base.OnResize(e); 102 | Invalidate(); 103 | } 104 | 105 | protected override void OnPaint(PaintEventArgs e) 106 | { 107 | base.OnPaint(e); 108 | if (_buffer != null) 109 | { 110 | Graphics gfx = e.Graphics; 111 | gfx.DrawImage(_buffer, _offset); 112 | } 113 | } 114 | 115 | public Point PixelToCell(int x, int y) 116 | { 117 | int cx = (x - _offset.X) / (_coreView.Width + _coreMargin); 118 | int cy = (y - _offset.Y) / (_coreView.Height + _coreMargin); 119 | return new Point(cx, cy); 120 | } 121 | 122 | public Point PixelToCell(Point pixel) 123 | { 124 | return PixelToCell(pixel.X, pixel.Y); 125 | } 126 | 127 | public Grid.Entry Pick(Point pixel) 128 | { 129 | Point corePos = PixelToCell(pixel); 130 | if (_data.Entries.Contains(corePos.X, corePos.Y)) 131 | return _data.Entries[corePos.Y, corePos.X]; 132 | else 133 | return null; 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /CoreSocietyTests/CoreSocietyTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {86B379FB-4E9F-4ABF-83DF-A52045897574} 7 | Library 8 | Properties 9 | CoreSocietyTests 10 | CoreSocietyTests 11 | v4.5 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | {718c47a5-fd90-44eb-9382-475e8a6171db} 60 | CoreSociety 61 | 62 | 63 | 64 | 65 | 66 | 67 | False 68 | 69 | 70 | False 71 | 72 | 73 | False 74 | 75 | 76 | False 77 | 78 | 79 | 80 | 81 | 82 | 83 | 90 | -------------------------------------------------------------------------------- /CoreSocietyTests/IndexerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using CoreSociety; 5 | 6 | namespace CoreSocietyTests 7 | { 8 | [TestClass] 9 | public class IndexerTest 10 | { 11 | [TestMethod] 12 | public void Clamp1D() 13 | { 14 | List data = new List() { 0, 1, 2, 3 }; 15 | Indexer idx = new Indexer(data, ClampMode.Clamp); 16 | Assert.AreEqual(0, idx[-1]); 17 | Assert.AreEqual(1, idx[1]); 18 | Assert.AreEqual(3, idx[5]); 19 | } 20 | 21 | [TestMethod] 22 | public void Repeat1D() 23 | { 24 | List data = new List() { 0, 1, 2, 3 }; 25 | Indexer idx = new Indexer(data, ClampMode.Repeat); 26 | Assert.AreEqual(3, idx[-1]); 27 | Assert.AreEqual(2, idx[-2]); 28 | Assert.AreEqual(1, idx[1]); 29 | Assert.AreEqual(1, idx[5]); 30 | Assert.AreEqual(0, idx[8]); 31 | } 32 | 33 | [TestMethod] 34 | public void Clamp2D() 35 | { 36 | List data = new List() { 37 | 00, 01, 02, 38 | 10, 11, 12, 39 | 20, 21, 22 }; 40 | Indexer idx = new Indexer(data, 3, ClampMode.Clamp); 41 | Assert.AreEqual(0,idx[-1, 0]); 42 | Assert.AreEqual(0,idx[0, -1]); 43 | Assert.AreEqual(0,idx[0, 0]); 44 | Assert.AreEqual(12,idx[1, 2]); 45 | Assert.AreEqual(12,idx[1, 3]); 46 | Assert.AreEqual(22,idx[3, 3]); 47 | } 48 | 49 | [TestMethod] 50 | public void Repeat2D() 51 | { 52 | List data = new List() { 53 | 00, 01, 02, 54 | 10, 11, 12, 55 | 20, 21, 22 }; 56 | Indexer idx = new Indexer(data, 3, ClampMode.Repeat); 57 | Assert.AreEqual(20,idx[-1, 0]); 58 | Assert.AreEqual(2,idx[0, -1]); 59 | Assert.AreEqual(0,idx[0, 0]); 60 | Assert.AreEqual(12,idx[1, 2]); 61 | Assert.AreEqual(10,idx[1, 3]); 62 | Assert.AreEqual(0,idx[3, 3]); 63 | } 64 | 65 | [TestMethod] 66 | public void Wrap2D() 67 | { 68 | List data = new List() { 69 | 00, 01, 02, 70 | 10, 11, 12, 71 | 20, 21, 22 }; 72 | Indexer idx = new Indexer(data, 3); 73 | Assert.AreEqual(20, idx[-1, 0]); 74 | Assert.AreEqual(2, idx[0, -1]); 75 | Assert.AreEqual(0, idx[0, 0]); 76 | Assert.AreEqual(12, idx[1, 2]); 77 | Assert.AreEqual(20, idx[1, 3]); 78 | Assert.AreEqual(10, idx[3, 3]); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /CoreSocietyTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CoreSocietyTests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CoreSocietyTests")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("241c2c36-c41d-48a1-b016-621560f0e8f2")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /CoreSocietyTests/SerializationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CoreSociety; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | namespace CoreSocietyTests 6 | { 7 | [TestClass] 8 | public class SerializationTests 9 | { 10 | [TestMethod] 11 | public void Base64CoreEncoding() 12 | { 13 | Core core = new Core(); 14 | string s = core.Encode(); 15 | core.Decode(s); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Documentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lithander/CoreSociety/5356a00f3f3f7449996ea264dae6fa19b99caaf0/Documentation.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CoreSociety 2 | =========== 3 | 4 | Core Society is a digital organism simulator based on a grid of programmable Cores. 5 | Not unlike a cellular automata a core can affect the state of its 4 direct neighbours. 6 | 7 | Each core has 256 words of memory and an intruction pointer pointing at a specific memory adress. When the core gains execution focus that word is interpreted as an instruction. The instruction set is similar to that of ordinary CPUs and allows the core to act like a tiny computer. It includes the ability to reserve and release energy which is used up by executing instructions and also determines which core is the next in line to execute: the core with the currently highest unbound energy! 8 | 9 | There are no free instructions and one core will always have execution focus. So even a grid only consisting of uninitialized cores will leak energy. 10 | 11 | The simulator ships with a handful of missions. The task is usually to beat a certain score threshold by defining the initial memory layout of a subset of the grid's cores. As soon as the simulation starts there's no way to interact with the outcome so you have to come up with a smart strategy, an efficient implementation and that usually means doing lot's of iterations. 12 | 13 | All but the most basic missions will require your program to write to the memory of adjacent cores to change their program and thus make them work towards your goal. Usually the grid is initialized with "enemy" cores who will try to prevent you from achieving a high score by spending all their energy to decrease the score. So the first part of the sim is usually spend on getting board control, then you can spend the remaining total energy budget on getting the score up. 14 | 15 | ***Getting started*** 16 | 17 | Download the repository and just start the prebuild executable (CoreSociety.exe) or build it yourself. 18 | 19 | Click on the top left icon to open a scenario. A click on the 'Play' Icon starts the simulation. 20 | 21 | You can click on a listing in the 'Deck' to open a second window that allows you to modify the listing which defines a core's memory contents. That way you can change the initial state of the simulation to attain a favorable outcome. 22 | 23 | To learn more about the instruction set and how to program a core have a look at the Documenation.pdf. 24 | 25 | Last but not least there are reference solutions supplied if you are stuck with a mission. 26 | 27 | Have fun! 28 | 29 | -------------------------------------------------------------------------------- /Scenarios/Demo.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | In this demonstration the green core is calculating primes, supported by the grey cores who provide it with energy! The blue cores try to prevent the red core from taking over the board by spending their energy to keep a shield up and supporting neighbours. 4 | 50000 5 | 6 | //next candidate 7 | next: 8 | INC _candidate 9 | SET _sqrt _candidate 10 | SQT _sqrt 11 | //init divisor 12 | SET _divisor !1 13 | factorize: 14 | INC _divisor 15 | //test for prime 16 | SET _temp _candidate 17 | MOD _temp _divisor 18 | //if divisor divides goto start 19 | IFZ _temp 20 | NXT next 21 | //if divisor < sqrt(pc) divisor++ 22 | IFL _divisor _sqrt 23 | NXT factorize 24 | //we have a new prime 25 | //copy prime to next free slot 26 | SET ~_out _candidate 27 | INC _out 28 | //if slots remaining goto start 29 | IFL _out !00FF 30 | NXT next 31 | JMP !0 32 | 33 | [30] 34 | _candidate: 35 | 1 36 | _sqrt: 37 | 0 38 | _divisor: 39 | 0 40 | _temp: 41 | 0 42 | _out: 43 | 50 44 | 45 | main: 46 | SET _com !0 47 | SET _dir !0 48 | TGT _dir 49 | 50 | boost_loop: 51 | RDW _a _com 52 | IFN _a !ABCD 53 | NXT break 54 | 55 | BST !50 56 | 57 | break: 58 | INC _dir 59 | TGT _dir 60 | IFL _dir !4 61 | NXT boost_loop 62 | 63 | //targeting self! 64 | query_shield: 65 | QSE _a 66 | IFE _a !FF 67 | NXT main 68 | SET _b !FF 69 | SUB _b _a 70 | SET _com !ABCD 71 | ISE _b 72 | NXT query_shield 73 | 74 | _a: 75 | 0 76 | _b: 77 | 0 78 | _dir: 79 | 0 80 | _com: 81 | 0 82 | 83 | 84 | evaluate: 85 | TGT !0 86 | QSE _a 87 | IFS _a 88 | NXT drill 89 | 90 | RDW _a 0 91 | IFE _a !A101 92 | NXT friend_ahead 93 | 94 | prepare_copy: 95 | SIP 85 96 | SET _a !0 97 | copy: 98 | STW ~_a ~_a 99 | INC _a 100 | IFL _a !end 101 | NXT copy 102 | 103 | IFE 0 !A101 104 | NXT boost 105 | turn: 106 | INC 0 107 | NXT evaluate 108 | 109 | boost: 110 | BST !F 111 | NXT boost 112 | 113 | drill: 114 | WKN !F 115 | SIP F 116 | NXT evaluate 117 | 118 | friend_ahead: 119 | IFE 0 !A100 120 | NXT turn 121 | score: 122 | ISC !F 123 | NXT score 124 | 125 | end: 126 | 127 | _a: 128 | 0 129 | _turned: 130 | 131 | 132 | 133 | TGT !0 134 | BST !F 135 | JMP !FF 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /Scenarios/Mission01.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | Click on the first entry in the Deck! Write a program to create as much score as possible. Close to 50k is possible! 4 | 50000 5 | 6 | //Write code here! 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Scenarios/Mission02.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | Write a program that copies itself into neighbouring cores and then generates as much score as possible. 20k or higher is possible! 4 | 50000 5 | 6 | //Write your code here! 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Scenarios/Mission03.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | Write a program that copies itself to all blue cores. Then generate as much score as possible. 15k or more is possible! 4 | 100000 5 | 6 | //Write your code here! 7 | 8 | ISE !F 9 | NXT 0 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /Scenarios/Mission04.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | You may only edit the green listing. To generate a highscore you need to overcome the blue shielded cores and overwrite the red cores that are programmed to decrease score. 25k or higher is possible! 4 | 100000 5 | 6 | 7 | DSC !F 8 | NXT 0 9 | 10 | 11 | QSE _a 12 | IFG _a !F0 13 | NXT decrease_score 14 | ISE !F 15 | NXT 0 16 | 17 | decrease_score: 18 | DSC !F 19 | NXT 0 20 | 21 | _a: 22 | 0 23 | 24 | //Write your code here! 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /Scenarios/Mission05.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | You may only edit the green listing. To generate a highscore you need to overcome the blue shielded cores and overwrite the red cores that are programmed to decrease score. 230k or higher is possible! 4 | 500000 5 | 6 | 7 | DSC !F 8 | NXT 0 9 | 10 | main: 11 | SET _com !0 12 | SET _dir !0 13 | TGT _dir 14 | 15 | boost_loop: 16 | RDW _a _com 17 | IFN _a !ABCD 18 | NXT break 19 | 20 | BST !50 21 | 22 | break: 23 | INC _dir 24 | TGT _dir 25 | IFL _dir !4 26 | NXT boost_loop 27 | 28 | //targeting self! 29 | query_shield: 30 | QSE _a 31 | IFE _a !FF 32 | NXT main 33 | SET _b !FF 34 | SUB _b _a 35 | SET _com !ABCD 36 | ISE _b 37 | NXT query_shield 38 | 39 | _a: 40 | 0 41 | _b: 42 | 0 43 | _dir: 44 | 0 45 | _com: 46 | 0 47 | //Write your code here! 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /Scenarios/Solutions/Mission01.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | Click on the first entry in the Deck! Write a program to create as much score as possible. Close to 50k is possible! 4 | 50000 5 | 6 | ISC !FE 7 | NXT 0 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Scenarios/Solutions/Mission02.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 50000 4 | Write a program that copies itself into neighbouring cores and then generates as much score as possible. 20k or higher is possible! 5 | 6 | [1] 7 | 0 8 | eval_target: 9 | TGT 1 10 | RDW 0 5 11 | IFS 0 12 | NXT next_target 13 | 14 | prepare_copy: 15 | SIP 15 16 | SET 0 !1 17 | copy: 18 | STW ~0 ~0 19 | INC 0 20 | IFL 0 !end 21 | NXT copy 22 | SIP 2 23 | BST !22 24 | 25 | next_target: 26 | INC 1 27 | IFL 1 !4 28 | NXT eval_target 29 | 30 | work: 31 | ISC !F 32 | NXT work 33 | end: 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /Scenarios/Solutions/Mission03.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | Write a program that copies itself to all blue cores. Then generate as much score as possible. 15k or more is possible! 4 | 100000 5 | 6 | ISE !1 7 | eval_target: 8 | TGT _tgt 9 | QSE _a 10 | IFZ _a 11 | NXT prepare_copy 12 | INC _tgt 13 | IFE _tgt !4 14 | NXT score 15 | NXT eval_target 16 | 17 | prepare_copy: 18 | SIP 20 19 | SET _a !end 20 | copy: 21 | DEC _a 22 | STW ~_a ~_a 23 | IFS _a 24 | NXT copy 25 | SIP 0 26 | 27 | boost: 28 | BST !40 29 | NXT boost 30 | 31 | score: 32 | ISC !FF 33 | NXT score 34 | end: 35 | _tgt: 36 | 1 37 | _a: 38 | 0 39 | 40 | ISE !F 41 | NXT 0 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /Scenarios/Solutions/Mission04.xml: -------------------------------------------------------------------------------- 1 |  2 | 100000 3 | You may only edit the green listing. To generate a highscore you need to overcome the blue shielded cores and overwrite the red cores that are programmed to decrease score. 25k or higher is possible! 4 | 5 | 6 | DSC !F 7 | NXT 0 8 | 9 | 10 | QSE _a 11 | IFG _a !F0 12 | NXT decrease_score 13 | ISE !F 14 | NXT 0 15 | 16 | decrease_score: 17 | DSC !F 18 | NXT 0 19 | 20 | _a: 21 | 0 22 | 23 | 24 | evaluate: 25 | TGT !0 26 | QSE _a 27 | IFS _a 28 | NXT drill 29 | 30 | RDW _a 0 31 | IFE _a !A101 32 | NXT friend_ahead 33 | 34 | prepare_copy: 35 | SIP 85 36 | SET _a !0 37 | copy: 38 | STW ~_a ~_a 39 | INC _a 40 | IFL _a !end 41 | NXT copy 42 | 43 | IFE 0 !A101 44 | NXT boost 45 | turn: 46 | INC 0 47 | NXT evaluate 48 | 49 | boost: 50 | BST !F 51 | NXT boost 52 | 53 | drill: 54 | WKN !F 55 | SIP F 56 | NXT evaluate 57 | 58 | friend_ahead: 59 | IFE 0 !A100 60 | NXT turn 61 | score: 62 | ISC !F 63 | NXT score 64 | 65 | end: 66 | 67 | _a: 68 | 0 69 | _turned: 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /Scenarios/Solutions/Mission05.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 500000 4 | You may only edit the green listing. To generate a highscore you need to overcome the blue shielded cores and overwrite the red cores that are programmed to decrease score. 230k or higher is possible! 5 | 6 | 7 | DSC !F 8 | NXT 0 9 | 10 | main: 11 | SET _com !0 12 | SET _dir !0 13 | TGT _dir 14 | 15 | boost_loop: 16 | RDW _a _com 17 | IFN _a !ABCD 18 | NXT break 19 | 20 | BST !50 21 | 22 | break: 23 | INC _dir 24 | TGT _dir 25 | IFL _dir !4 26 | NXT boost_loop 27 | 28 | //targeting self! 29 | query_shield: 30 | QSE _a 31 | IFE _a !FF 32 | NXT main 33 | SET _b !FF 34 | SUB _b _a 35 | SET _com !ABCD 36 | ISE _b 37 | NXT query_shield 38 | 39 | _a: 40 | 0 41 | _b: 42 | 0 43 | _dir: 44 | 0 45 | _com: 46 | 0 47 | init: 48 | ISE !1 49 | TGT _dir 50 | SET _com !F0F0 51 | 52 | copy_loop: 53 | QSE _a 54 | IFZ _a 55 | NXT copy 56 | return_copy: 57 | INC _dir 58 | MOD _dir !4 59 | TGT _dir 60 | IFS _dir 61 | NXT copy_loop 62 | 63 | interact_loop: 64 | //read com 65 | RDW _a _com 66 | //friend needs help? 67 | IFG _a !F0F0 68 | NXT support 69 | //not a friend? 70 | IFL _a !F0F0 71 | NXT attack 72 | INC _dir 73 | TGT _dir 74 | IFL _dir !4 75 | NXT interact_loop 76 | 77 | SET _com !F0F0 78 | work: 79 | ISC !5F 80 | NXT work 81 | 82 | support: 83 | DEC _a 84 | SET _com _a 85 | BST !30 86 | NXT interact_loop 87 | 88 | attack: 89 | SET _com !F0F2 90 | inner_attack: 91 | WKN !F 92 | QSE _a 93 | IFZ _a 94 | NXT copy 95 | NXT attack 96 | 97 | copy: 98 | SET _com !F0F1 99 | SIP end 100 | SET _a !end 101 | copy_word: 102 | DEC _a 103 | STW ~_a ~_a 104 | IFS _a 105 | NXT copy_word 106 | STW _dir _dir 107 | SIP 0 108 | NXT return_copy 109 | 110 | end: 111 | 112 | [40] 113 | _com: 114 | 0 115 | _a: 116 | 0 117 | _dir: 118 | 0 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | --------------------------------------------------------------------------------