2

Update Link to the C# Solution Project from a user who answered me: https://github.com/TedDawkin/C64_AI_Movement

Update

I found it - if someone is interested just use the link to the thread in C64 Forum: http://www.lemon64.com/forum/viewtopic.php?p=712902#712902 where I discussed the topic (with myself). Funny how simple it was in the end. Not so funny that it took me over 2 weeks.

I will post the BASIC to C# code later and "answer" my own Question.

If someone cares and dont want to go to the forum link, here is how it works in C64 basic.

30110 IF KS(S)=0 THEN GOSUB 30400 : GOTO30105
30400 POKE 211,20: POKE214,18: SYS CS: PRINT"SPIELER"F
30405 Y=INT(KP(S,F)/40)
  SYS CR, KP(S,F)-40*Y, Y
  X=PEEK(UA)-1
  Y=PEEK(UA+1)-40
30410 IF PEEK(UA+2)=1 OR PEEK (UA+3)=1 GOTO 30420
30415 IFINT(RND(1)*2)=0ORGW(KS(S),F)<4GOTO30450
30420 IFX=0THENX=Y:GOTO30215
30421 IFY<>0GOTO30450
30425 GOTO30215
30450 IFX<>0ANDRI(F)<>(1+2*(X=1))THENP=X:GOSUB30490:IFP=0THENRETURN
30451 IFY<>0ANDRI(F)<>(40+80*(Y=1))THENP=Y:GOSUB30490:IFP=0THENRETURN
30455 IFX<>0ANDRI(F)<>(1+2*(X=1))GOTO30460
30456 IFRI(F)<>-1THENP=1:GOSUB30490:IFP=0THENRETURN
30457 IFRI(F)<>1THENP=-1:GOSUB30490:IFP=0THENRETURN
30458 GOTO30465
30460 IFY<>0ANDRI(F)<>(40+80*(Y=1))GOTO30465
30461 IFRI(F)<>-40THENP=40:GOSUB30490:IFP=0THENRETURN
30462 IFRI(F)<>40THENP=-40:GOSUB30490:IFP=0THENRETURN
30465 RETURN
30490 Q=KP(S,F)+P:IFQ<0ORQ>520OR(PEEK(BR+Q)<>32ANDPEEK(BR+Q
<>96)THENRETURN
30491 POKEBR+KP(S,F),32:KP(S,F)=Q:POKEBR+KP(S,F),193:POKEFR+KP(S,F),6
30492 RI(F)=P:P=0:RETURN

some hints:

X = moved right (1), left (-1), up (-40) or down(40)
P = Position. There is no Y because the next/prev line is
40 characters away. (C64 Screen =  40 Columns and 25 Rows)
S = switches between 0 and 2 to determine if its human or ai turn
KP(S,F) = Offset-Position in Video-Memory-Adress
BR = Start-Adress of Video-Memory
32 = 0x20 = Space to clear old position
193 = Ascii-Character used as pawn for player and ai
6 = Mark field as AI (Human position is marked with 0x0b)
F = Playernumber
RI(F) = dont know yet

Original Question:


Working on a remake and trying to understand C64-Code I am struggling with the AI Movement. Working over a week on it, I cant reproduce the 100% same behavior.

Andy
  • 49,085
  • 60
  • 166
  • 233
user312430
  • 39
  • 3
  • Remark: I tried a simple A* and a more complex one. The movement is not the same as in the C64 Original especially if the AI comes close to obstacles. With more then one AI the Range and Movement gehts even worse. This code is what I thought happend in the C64 Basic and assembler code. – user312430 Dec 25 '15 at 22:32
  • Then that what you though about the assembler code must have been wrong. Go reverse engineer it harder (don't forget about the legal aspects of reverse engineering, too..), I don't think anybody here has experience with the exact AI movement code of an old c64 game and is able to help you with that. – Maximilian Gerhardt Dec 25 '15 at 22:43
  • Also your circles and the trash cans (and also other obstacles) in the video have not the same configuration. This makes it harder to compare the two games. If you want to compare, use exactly the same configuration. – Olivier Jacot-Descombes Dec 25 '15 at 23:00
  • I remember this. Put the conversion from BASIC to C# on [github](https://github.com/TedDawkin/C64_AI_Movement "https://github.com/TedDawkin/C64_AI_Movement") Getting to know [Unity](https://unity3d.com) I am working on a remake, just for fun. – Ted Dawkin Apr 11 '17 at 11:08

1 Answers1

1

To answer my question: Yes, an Ai can act randomly by using RND and I totally overlooked that.

For the in-depth discussion go to the Forum-Thread

There where other stumbling blocks that will maybe help if you want to debug/reverse engineer some stuff.

  • I always read the BASIC-Code without syntax highlighting and formatting. By doing this I missed some things and made errors.
  • Positions where marked in screen memory
  • Positions where not Point(x,y) or array[x,y] but an integer 0-999 representing the 25 rows and 40 columns of the C64-Screen
  • With the assembler part, I was to much in detail. It would have been better to look at 5 to 10 commands in a row and think about what could happend (without debugging) instead of getting lost in JSRs while debugging
Cactus
  • 27,075
  • 9
  • 69
  • 149
user312430
  • 39
  • 3