Its All About The Base
When Avalon started climbing the charts I decided to follow up with another game using the same game engine with some improvements. I started off looking at the graphics plot system and added a few go faster tweaks. I also enhanced the game engine to give me a greater number of adventure steps. I wanted Dragontorc to be bigger and better, a tall order considering I had a job to squeeze Avalon into the Spectrum's meagre memory. Working on the technical aspects gave me time to consider the plot. I needed inspiration so visited the library and came back with a stack of books including Joy Chant's The High Kings. This is a very well presented collection of old Celtic tales which are told by Arthur and his knights as they sit around their camp fire. It is sad that the old Celtic tales are not really part of our lives, At school we learn old Jewish tales and now the tales of many other religions yet there is a rich heritage of native tales that are part of our heritage.
I liked the idea of Tolkien's of layers of history that underpin the Lord Of The Rings. Sometimes they appear as mere glimpses which give them even more mystery. I started thinking about the history of Britain and liked the idea of hidden history that is mostly obscured. So the idea of the lost realms was born I based my lost realms on ancient tribal regions of pre Roman Britain. The period I chose was the time just after the fall of Roman Britain when the surviving Britons may very well have tried to resurrect ancient kingdoms in the struggle for survival. As evidence was scanty for the period it gave me licence to invent what I needed. Avalon was also set in this period with references to the old Celtic legends of Arthur rather than the Anglo Saxon rewrite that tried to claim Arthur as their own. Thus the sword was called Caliburn rather than Excalibur.At the end of Avalon it ended up in the stone to match popular myth although in the old legends there was actually more than one sword. There was the one in the stone and the one given by the lady of the lake. I planned a third episode that would include a young Arthur and would end up with him reclaiming the sword but this did not get written.
So to make the plot bigger I opened up the scenario to include locations all over Britain. Each location was based on a lost realm plus one for the final confrontation of the evil queen. I wanted to give the feeling that the player was not the only party trying to recover the lost crowns. Originally I was going to have Anglo Saxon warriors gradually move across the map so it was a race against time. This idea was eventually put to the side, the only relic of it being the warrior and ship on the screen surround.
I drew up a list pf the spells and kept the ones I liked and added few new ones. I also added a system of "curses". Various things could affect the player giving him failing heath, blindness, slow motion etc. The system allowed for each to have a cure. I enhanced the spell system to allow a quick exit from spell mode by moving the joystick sideways. This was a result of watching people struggle to get out of spell mode and run when attacked by an enemy.
I did some work on the AI to improve the way the characters acted. In Avalon there was a system that chose a movement pattern based on how afraid the enemy was. I made this into a two dimensional system by added a like/dislike dimension. So the relation you had with a character and their fear status were used to choose a movement pattern. You could affect the like/dislike factor by attacking or doing friendly actions such as giving items that the characters liked. Fear was affected by using magic or by managing to kill an enemy. It was a very advanced system for its time and allowed the player to make allies which were needed to attack invisible enemies in the final scenario.
I enhanced the graphic look by including outdoor scenes such as the stone rings and wood lands. They are all built out of the basic theatre backdrop room sections. I used the same style of graphics throughout where I Just drew the highlights on the background objects. That way you can suggest detail that is not there and the brain fills in the rest.
As the majority of the code was the same the game was developed very quickly. I was still not using an assembler but at this stage had hooked up a disassembler to a Centronics printer and managed to get it to read my label table that I used in my hex loader. This gave me a source listing with my own labels in it allowing me to check that my hand assembly was correct and allowing me to throw away all the original squared paper with the hand written code.
Andrew and I play tested the adventure for me with no cheats. It was a pain testing when you played for days then found an event code was wrong so could not complete an adventure step. I used to fix the data with Andrew's peek/poke monitor and carefully record all the changes for the next test run. In the end I could run through the whole game in a few hours.
We had the game launch at the London Museum which included a brief tour of the dark age exhibits. Andrew Hewson used to work at the British Museum so managed to borrow a solid gold copy of a real Celtic torque which unfortunately was copyrighted (even though it was a copy) so we could not take photos .
I was struggling to get the game world working. After a while everything seemed to stop doing things. Each bug I found gradually made things a bit better. I realised it was time to get some proper bases in the game. I was using ships as bases and if they had multiple docks they were so close the ships would crash into each other. So a set of full size base parts were needed so I could construct a variety of bases.
I needed parts to build:
A port. This would need dock pads and warehouses.
A space dockyard. This needed a dock where ships and parts could be built,
Then a set of manufacturing bases for asteroid processing.
A control base for establishing ownership of sectors.
On a sunny day I took a squared pad into the garden and sketched vaious space bases then tried to analyse the drawing to see what sort of construction kit I needed to be able to build them. I studied pictures of the ISS and other proposed bases. In the end I came up with a set of essential pieces, mainly a central hub which was hexagonal so could be joined to in various ways, a basic tunnel section to join to the hub, then various bits and pieces that could hang off the tunnels. For the industrial processes I designed a general platform upon which I could bolt various other parts.
I ran into trouble when I started putting the parts into the part editor. It was years since I last used it, I could no longer remember how t worked and I just could nit do what I wanted. So I spent a couple of weeks tweaking the editor to allow it to make the pieces I required. Then I tried to use the parts in the in game ship building editor. All my ships had been so far built from Z aligned pieces so I found that bases with right angle joins this way and that did not work. So back to the drawing board, I had to remember how that editor worked and amend some of the trickiest routines. The worst one was the one that worked out if you plug in a join pointed in na particular direction into another and take account of the parents direction you can multiply all the matrices and come up with where the joining piece has to sit. It kept failing and I found it was the join data coming from the part editor. It was giving incorrect angles for some of the joins. I fixed that and that mucked up every ship I had built. Sometimes you have to go backwards to go forwards.
|What happens when the joins are wrong|
So as usual a few days planned work grew into a month. It was a relief when I finally got a base in the game. It instantly changed the look and feel of the game having giant objects. The trouble was for some reason they were not colliding with anything. It took ages to find the bug. Somewhere during my editor revamp I had changed the part code from hull to chunk so I could identify base pieces. This was not recognised by the collision system. They did collide with things but did not know what action to take.
I had a few problems because the prime piece of the base the hub had to be set in a vertical direction then all the other base pieces rotated to fit. Previously all bases had been Z aligned. After a false start I realised all I had to do was change the code to place the first piece in the required direction and the existing code transformed the positions of all the other bits automatically, result!
Now the tricky bit, can the AI ships build the new bases? I chose a construct mission and watched my ship in AI mode crash into a base that set a NAV point inside it. As the bases were much bigger the NAV point system needed updating. The constructed parts were launched from the shipyard ok but now things were bigger it was hard to get the ships to collect them from behind as that meant approaching from the base. The solution, I launched the parts backwards so the ships can approach them from the rear and still be away from the base.
|Dock yard building base parts|
Getting the above working showed a few loopholes in the world design I needed to plug. When base parts were accidently destroyed the ships got confused and sometimes would cause a crash. When the Seiddab start attacking there will be a lot of that. I had to cater for a couple of situations. The part the ship was carrying might be destroyed. Then the mission should cancel and be reordered. Or the part the part is joining to may be destroyed. Then the ship needed to find something useful to do with the part. While I was at it I did the same for ships carrying freight and asteroids. Some of this code existed and just needed bringing together.
I also added models for sentinels, forts and mines. These automatically protect various resources . The sentinels record who has passed and allow a display of the enemy positions. I added guns to the sentinels to give a little protection. They try to keep a low profile but can point toward an attacker and fire a blast to defend themselves.
|Approaching dock pad at a port|
So all in all this session has been really up and down, at times I am wondering why I ever made the world realistic and whether I can actually get it working then feeling really elated when I see some new graphics in the game. It is one of the reasons I leave graphics to late in the project. I find its best to get the most boring bits done as early as possible. Space battles are now starting to break out, what I need to is to implement the save game so I can run scenarios up to an interesting point then save them so you can get straight into the action.
Turing Machine Revisited
I think I tweeted this once or maybe even blogged about it, but here is a larger explanation with my idea of using it to evolve algorithms.
Turing showed that a simple machine that could read a binary string of digits from a " tape" and change them if needed could run any program and was equivalent to any computing device that can be invented. I changed the format very slightly for my version . The tape in this version is the character string sTape. Turing specifies an infinitely long tape but you only need that for programs that run forever. His machine operates on a series of instructions. Each line of the Turing program reads a digit from the tape and decides on one of two actions depending on the data being 1 or 0. Each line is essentially an if else structure. The actions are what to write to the tape and which direction to move it. Each of the branches can go to another line of the Turing program. Thus loops, if else, call structures can all be implemented.
The actual Turing machine is implemented in the macro OP. This allows lines of code to be easily listed.
*ptr reads a character form the tape. Then it decides if it is zero or not and goes down the appropriate branch. Each branch can write a one or a zero, move the tape left or right and then got to another line of the program or eventually stop.
The Turing code is hard to write but you can write anything with a bit of thought. You have to decide about how numbers are going be represented on the tape and process them accordingly. Also where results are written to the tape had to be worked out and the program may pend most of its time moving the tape between input and output. You an extend the idea to use more then one tape, ascii rather tan bit input but the point was Turing showed all these were technically equivalent and were optimisations rather than fundamentally changing what could be done.
Turing investigated what is called the stopping problem. You can write an algorithm to do something but you do not know whether the code will actually ever stop and give you the result. He imagined a program that examined all programs to see whether they stopped. He proved no such algorithm existed so you could not know whether a program will actually stop or not.
In the book The Emperors New Mind there is a listing of generic Turing Machine program that can run any Turing program. It is pages of ones and zeroes I doubt it would ever work having typed in more meaningful programs in days gone by from magazines and never getting them working.
I was experimenting with this as it ran in a sandbox with a limited instruction set of 1 generic instruction. I was trying to evolve Turin programs by randomly taking bits of one set of code and joining them with another version of the code. you then run it for a limited number of steps and assign a fitness weight to that version of the code by looking at the results and comparing them with a set of rules. I tried to evolve a program to calculate a square root as that is quite easy to test for accuracy and give a score. Initially I got good results for one input number but could not get it evolved to do the general case of any input number. I used to play around with these conundrums in my lunch hour to keep me amused.
I changed the way Turing instructions were encoded slightly so they contained no redundant bits so can be mutated but still always give a valid code (but maybe not a valid program You need to provide contingency for the tape length being exceeded and the GOTO number being excessive of infinite loops. Here is just the basic version for simplicity. It is surprisingly small.
#define RIGHT -1
#define LEFT +1
#define OP(Label,Go0,Op0,Mv0, Go1,Op1,Mv1)\
void DoTuringMachine ()
TCHAR* ptr = NULL;
TCHAR sTape = "0000000000000000000000001111100";
long lHigh =0;
long lLow =0;
ptr = sTape+strlen(sTape)-1; //start at far right
OP (S0, S0,0,RIGHT, S1,0,RIGHT); //bypass 00 destroy first1
OP (S1, S2,1,LEFT , S1,1,RIGHT); //bypass 111 add1 toleft
OP (S2, S3,0,RIGHT , S4,0,RIGHT);
OP (S3, Exit,1,RIGHT ,S3,1,RIGHT);
OP (S4, S5,1,LEFT , S4,1,RIGHT);
OP (S5, S2,1,LEFT , S5,1,LEFT);
Another idea I explored came from a book about Chaos Theory. A researcher programmed a logic grid that employed an array of simulated logic gates. Each accepted input from two others and set its state according to the rules of the gate. For example if it was an OR then if either input was 1 it sets it to a one. What they found as that the array settled down usually in an amazingly few number of updates into stable set of states that cycled. I reckon the brain starts off doing something similar with a neural network and then finds uses for patterns that just happen to match , rather than constructing them from scratch.
I programmed a logic array and then tried to evolve it by changing the gates. My intention was to combine the idea with the Turin code so rather than the if/else each line can have any logic gate and two inputs. I would love to be able to evolve game code rather than write it the hard way. I get these crazy ideas now and then but am too busy to follow them through. Maybe it will inspire somebody to write the next generation AI.