Laser squad a.i.

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Laser squad a.i.

Post by Wall_Axe »

Do games like laser squad and Arnhem use the min/max algorithm?

The problem is that each player has like 50 or more choices per round due to controlling large numbers of units so the min/max algorithm would take up ridiculous amounts of ram.
One way would be to make each unit either agressive defensive or do nothing,so that's only three moves per unit per round.
In laser squad a unit can shoot you and then retreat into cover, behind a corner for example.
Is that custom implemented or just behaviour that emerges from an algorithm?
User avatar
ketmar
Manic Miner
Posts: 713
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: Laser squad a.i.

Post by ketmar »

i didn't looked at the disasm, but i believe that it is just a set of finely tuned heuristics, plus some simple pathfinding. that's something even PC tactical games are using.

if i'd be asked to write such code, i'd assign weights to actions, weapons, etc, script some behaviour (like "shoot and retreat", and so on), and then spend monthes fine-tuning those weights and adding special code pathes until it started to feel "ok".

i bet Laser Squad does something like that too: evaluates several possible actions (attack, defend, change weapon and attack, etc.), and picks one that has the best weight. maybe with some randomness thrown in, to make it less predictable.
Ralf
Rick Dangerous
Posts: 2289
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Laser squad a.i.

Post by Ralf »

I also don't know but minimax sounds too ambitious.

Enemies may probably have several states - idle, guarding, patrolling, attacking etc. At each turn it is checked if they should change
their state (like see an opponent -> attack) and then they perform logic for their state.

I don't know how it is now but for many years (all 90s and 2000s for sure) AI in such games was objectively very crap.
In games like Warcraft you always started with a small group of units and enemy started with a big army. Because if it was equal then
the human player would beat computer almost immediately.
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: Laser squad a.i.

Post by AndyC »

Yeah, I'd imagine weighted actions with a bit of randomness to help keep things unpredictable. It's surprising how much you can fake the idea of emergent behaviours with such a system. I doubt the Spectrum is going to be doing anything like comprehensive game analysis on the best moves, not only is that RAM hungry but it would take ages on a Z80 CPU.
User avatar
WhatHoSnorkers
Manic Miner
Posts: 254
Joined: Tue Dec 10, 2019 3:22 pm

Re: Laser squad a.i.

Post by WhatHoSnorkers »

"The General" has some interesting "AI". There are 4 global states (you want to capture both farms), and it goes "which is it?"

1 I have no farms
2 I have North Farm
3 I have South Farm
4 I have both farms

and from there it does different things for infantry, cavalry and artillery, and keeps "counts" of "how long have I been doing this" and so on.

All in BASIC too.
I have a little YouTube channel of nonsense
https://www.youtube.com/c/JamesOGradyWhatHoSnorkers
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Laser squad a.i.

Post by Joefish »

Ralf wrote: Fri Jul 28, 2023 4:55 pm I don't know how it is now but for many years (all 90s and 2000s for sure) AI in such games was objectively very crap.
In games like Warcraft you always started with a small group of units and enemy started with a big army. Because if it was equal then
the human player would beat computer almost immediately.
This is true. It quickly became obvious playing Advance Wars that your opponent just does the same things over and over, given similar circumstances. The only thing that increases the challenge is the initial set-up of the battlefield giving them a huge advantage in numbers, weaponry, territory, or cover. They do at least seem to play by the same rules of progression and visibility the player is under.
User avatar
MatGubbins
Dynamite Dan
Posts: 1239
Joined: Mon Nov 13, 2017 11:45 am
Location: Kent, UK

Re: Laser squad a.i.

Post by MatGubbins »

Many many years ago I wrote a map editor for Laser Squad mainly for editing the moonbase level.


On the original moonbase map what I found was that the computer controlled troops were placed into the map from a pre-programmed list of starting places. These did not match up with some of the deployment squares at the start of the game, so some troops were closer to the main doors or in rooms that they shouldn't be in - little bit of cheating from the computer/programmer!

On any custom made moonbase maps the computer would ingore the new deployment squares and again place the troops into the pre-programmed squares. During a game on a custom made map the computer troops would follow a pre-programmed path that was defined by the original map and they would often keep bashing into a wall that was not supposed to be there. They sometimes would spin on their heels trying to find a way around the custom map and many times would fire at the invading troops even though a solid wall blocked their view. They would also rush to a pre-defined area of the map if any of the invading troops stepped into it thinking it was a important part to defend. This meant that the game had pre-defined areas that the troopers had to defend (the computer room) and were alerted when any main doors were opened or corridors were ventured into - all based on the original moonbase map data

This also applied to Reblestar (Firebird) where if the map was edited the defending robots that were situated in the rooms surrounding the main computer room would not see the invading troops if walls were removed from arond the outer rooms. They would see and attack the troops once they ventured into these rooms, this meant they were programmed to see a certain part of the map.
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Laser squad a.i.

Post by Wall_Axe »

Interesting,so it's scripted and possibly even custom for each map.

In the first scenario in laser squad you invade someone's house.
There is one dalek looking thing that can shoot you as soon as you step through a door.
It is a long shot down a long corridor.
The robot waits there no matter what.

Seems like it's very scripted then
User avatar
Morkin
Bugaboo
Posts: 3277
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: Laser squad a.i.

Post by Morkin »

I did wonder how Laser Squad AI worked. It's tricky to figure out as a player as it's hidden. However, you can see which direction the units are moving if you watch the compass during the computer's turn.

I may have imagined it, but from this it does look as if certain units have standard 'patrols' - i.e. before you're identified, it looks as if there's a set path for some enemy units, which would support @MatGubbins' observations.

It'd be interesting to see how behaviour changes for the whole enemy squad once a unit is spotted.

Rebelstar seemed a bit more simplistic. The enemy don't really engage until one of your units breaks into the base through an airlock, whereupon enemy units would make a beeline towards them. A good cheese tactic is to keep them in limbo by moving your units in and out on each side, causing the enemy ones to charge back and forth aimlessly. You can then try to pick them off while they're in the open.

...OK, so who's going to volunteer to disassemble both games? ;)
My Speccy site: thirdharmoniser.com
User avatar
ketmar
Manic Miner
Posts: 713
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: Laser squad a.i.

Post by ketmar »

Morkin wrote: Fri Jul 28, 2023 9:27 pm...OK, so who's going to volunteer to disassemble both games? ;)
easy deal. but who will read and properly comment the code after that? ;-)
marenja
Microbot
Posts: 108
Joined: Sun Dec 26, 2021 4:15 pm

Re: Laser squad a.i.

Post by marenja »

ketmar wrote: Fri Jul 28, 2023 9:44 pm easy deal. but who will read and properly comment the code after that? ;-)
Which tool do you use for disassembling? Does it handle DB segments correctly? We need to skip some segments as they are DB-data and not mc-code. Or we need to set start of mc-code after DB segment correctly so that some bytes that start mc part are not tied as end of DB part.
User avatar
Bedazzle
Manic Miner
Posts: 305
Joined: Sun Mar 24, 2019 9:03 am

Re: Laser squad a.i.

Post by Bedazzle »

marenja wrote: Sat Aug 05, 2023 2:46 pm Which tool do you use for disassembling?
Skoolkit

and

Ghidra

there is also IDA Pro, but it is commercial.
User avatar
ketmar
Manic Miner
Posts: 713
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: Laser squad a.i.

Post by ketmar »

yep, Skoolkit is prolly the best one for this kind of work. but long ago i started developing my own (because why not? ;-), which is using emulator execution traces, and tries to deal with self-modifying code too. of course, i never finished it. maybe someday…
User avatar
Bedazzle
Manic Miner
Posts: 305
Joined: Sun Mar 24, 2019 9:03 am

Re: Laser squad a.i.

Post by Bedazzle »

ketmar wrote: Sun Aug 06, 2023 5:06 pm but long ago i started developing my own (because why not? ;-), which is using emulator execution traces, and tries to deal with self-modifying code too.
I'm very interested in this! :o
User avatar
ketmar
Manic Miner
Posts: 713
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: Laser squad a.i.

Post by ketmar »

Bedazzle wrote: Sun Aug 06, 2023 9:29 pm I'm very interested in this! :o
sadly, it is not finished. in my case, "not finished" means "a pile of code that implements some PoC ideas". i'm planning to eventually return to it and produce something usable, though; that's why i mentioned it at all. it could be a handy tool for initial code analysis. sadly, i have no time to work on it right now, and there is nothing of value to pass around yet (i don't even know if i'll be able to run what i have). it was one of "what if" experiments, without real structure and such, and using a heavily modified version of my ZXEmut.

the idea was to use execution traces to determine what code is actually "reachable", and record all memory writes to executable code too. and there is some logic on top of that which tries to guess if something is just a variable, or we are dealing with dynamic code builders (like those in Firefly, for example). basically, if the changes are limited to LD args, jump conditions and such, then it should be a variable/simple logic. but if changes are very massive (often including copying code blocks via ldir/push, and the code itself consists of mostly byte transfers), then it should be some kind of JITing, and the analyzer tries to mark JIT building blocks and compiler routines as such, for human to decipher them later.

i still believe that the idea is workable, and it may even detect various kind of JITers (there is only so much practical ways to write blitter-compilers and such, after all). it simply needs some time to rewrite the thing to be manageable, and improve detection logic. it may even be able to detect some tilemap routines like collision detection and such.

if somebody wants to take the idea and do something with it, they are welcome. this is one of the cases when i'd love to use already existing tool instead of writing my own. ;-)
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Laser squad a.i.

Post by Wall_Axe »

Has any turned based strategy game been disassembled?

I think chaos would be something very demanding as each wizard can cast a spell from a wide selection,move, and move its units.

Those advanced WW2 games like Vulcan.

The Viking strategy game released by firebird.
User avatar
WhatHoSnorkers
Manic Miner
Posts: 254
Joined: Tue Dec 10, 2019 3:22 pm

Re: Laser squad a.i.

Post by WhatHoSnorkers »

I'm working on disassembling Caudillo, which is definitely a turn based game but is only 2 player. And it's a VERY slow process!
I have a little YouTube channel of nonsense
https://www.youtube.com/c/JamesOGradyWhatHoSnorkers
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Laser squad a.i.

Post by Wall_Axe »

interesting thanks

im wondering if there was a standard type of algorithm used as the spectrum is so limited in speed and size
User avatar
Bedazzle
Manic Miner
Posts: 305
Joined: Sun Mar 24, 2019 9:03 am

Re: Laser squad a.i.

Post by Bedazzle »

Wall_Axe wrote: Mon Aug 07, 2023 1:11 pm Has any turned based strategy game been disassembled?
Does anybody know status of Laser squad/Rebelstar/...?
I mean, for example, if I will go for disassemble it, and publish sources on github to all the world?
SteveSmith
Manic Miner
Posts: 724
Joined: Mon Nov 26, 2018 1:07 pm
Location: UK
Contact:

Re: Laser squad a.i.

Post by SteveSmith »

Wall_Axe wrote: Mon Aug 07, 2023 1:11 pm Has any turned based strategy game been disassembled?

I think chaos would be something very demanding as each wizard can cast a spell from a wide selection,move, and move its units.
I remember someone disassembling Chaos back in the 90's on c.s.s. IIRC the AI was quite simple:Choose an almost random spell, and it uses a heat map to determine threats and where to attack or avoid, and creatures attack the closest threat.
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Laser squad a.i.

Post by Wall_Axe »

Interesting thanks,
Arlorean
Drutt
Posts: 3
Joined: Mon Oct 16, 2023 10:44 am

Re: Laser squad a.i.

Post by Arlorean »

I made start on disassembling the original single player Rebelstar game using the Spectrum Analyser tool.

The current progress is in this GitHub repository:

https://github.com/Arlorean/Rebelstar

Image

It is slow going but I'm trying to get a better understanding of how the chance to hit and damage mechanics worked. There are a lot of data tables for weapons, units and map elements that aren't formatted anywhere currently but I'll try to add a data dump tool to format these at some point. I've not looked into SkoolKit but the Spectrum Analyser tool says it does export to that format as well.
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: Laser squad a.i.

Post by Wall_Axe »

that's really interesting, i would be interested in the a.i. of course.

It seems to be just seeking out the humans and shooting at them using the basics , line of sight, pathfinding etc. at a guess.

I think someone else mentioned they tend to take notice of where the player's units have entered the base
User avatar
ketmar
Manic Miner
Posts: 713
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: Laser squad a.i.

Post by ketmar »

actually, there is javascript version of Laser Squad. the author seems to use reverse-engineered ZX Laser Squad as a source for this recreation. there is also Rebel Star, but it is in java, and without sources. i am not sure if this is a recreation, or "reimagination", though, but at a first glance it looks like something that is close to ZX version.
marenja
Microbot
Posts: 108
Joined: Sun Dec 26, 2021 4:15 pm

Re: Laser squad a.i.

Post by marenja »

Arlorean wrote: Mon Oct 16, 2023 10:53 am I made start on disassembling the original single player Rebelstar game using the Spectrum Analyser tool.

The current progress is in this GitHub repository:

https://github.com/Arlorean/Rebelstar
Good news! Is anyone interested in sources of other games (Rebel Star II with aliens or Laser Squad)? The question is aimed to 2 groups. One group is those who are just curious to look inside the game. The other is able to do disassembling.

Probably the work will be much easier with some co-operation ... hm-m ... a sort of crowd disassembling?
Post Reply