Giter Site home page Giter Site logo

Comments (33)

mithrendal avatar mithrendal commented on May 27, 2024 2

Of course it would be cool to use some kind of scripting standard instead of a self-designed language, but I don't know if such a standard exists in the web

maybe we can try to use pure javascript as a replacement for "action sequence script" ... I will try tonight ...
I am not sure whether it will look simpler... maybe code will look more complex

this rather descriptive expression

j1right1=>1750ms=>j1fire1=>150ms=>j1fire0=>1600ms=>j1fire1=>400ms=>j1fire0=>j1right0

could become this

cmd("j1right1");wait(1750);cmd("j1fire1");wait(1600);cmd("j1fire0");cmd("j1fire1");wait(400);cmd("j1fire0");cmd("j1right0");

... is not looking so clean, what do you think ?

on the other side we would gain while() and all the other neat language stuff ..

what I dream of is playing archon with own code ... I think it is not cheating as @sy2002 said but winning with same weapons as the computer ... for example look on archon, as a kid we always played human vs human and never played against computer because the computer opponent is so damn hard ...

grafik

to be able to react in our script code to the enemy ... we would need of course the sprite on screen coordinates for our hero sprite and the enemy sprite and the enemies shooting projectile sprite which is engaging our hero sprite ...

do you think we can transfer them from the core into the javascript with a wasm_get_all_sprite_coordinates() method ?

we could also make a event based script API like this ...

onAppearance() -> tells us new x,y of a new sprite
onMove() -> tells us new x,y of a sprite
onVanish() -> tells us new x,y of a sprite which was just disabled (probably we have killed it)

in our script we could add Listeners to these Events and get more infos about the game situation in order to send the appropriate joystick commands for our hero back into the core ...

we could theoreticaly write a pacmen solver with it, no ?

@sy2002 of course it would be pure cheating when we offer a API to directly alter our heros or the enemies sprite coordinates e.g. with a poke ... πŸ˜‰
We would never allow that. Dirk ? Would we? As it is against the unwritten intergalactic moral rules of computer game culture

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024 2

grafik

But I guess it would be a little over the top for the intended purpose πŸ˜….

dirk ... we got it ... turing complete ... 😎

standard javascript scripting is the brand new hidden feature in the official version of vc64web ...

it is activated when the action script starts with js:

action commands are the same as the actions in action sequence script ... that is you can convert every action sequence script into a javascript (except the loop action ... which make no sense as you have the power of javascript)
'load"$",8,1'=>Enter becomes js:await action("'load\"$\",8'"); await action('Enter');
loop3(A=>150ms) becomes js:for(var loop=0;loop<3;loop++){await action("A"); await action("150ms");}
and so on ...

πŸ€” now that we have got the expression power ... I should really modifiy my auto defense pilot an add sinus wave flying maneuver forms to it, no?

from virtualc64web.

dirkwhoffmann avatar dirkwhoffmann commented on May 27, 2024 2

I think that will be a lot of fun for me ..

That's the import information!!! If we were a company, I would definitely go into the scene browser direction. But luckily, we are not a company. We can just implement what is most fun for us πŸ₯³.

Dirk can you give me an advice how to get the sprite position out of the core ?

I think it's best if you have a brief look at the v4.0 code in the dev branch. In this version (which uses the vAmiga SW architecture), every component has a getInfo() function. E.g., VICII::getInfo() returns a VICIIInfo struct which is declared in VICIITypes.h. This structure contains everything that is display in the Inspector's VICII panel:

typedef struct
{
    // Counters
    u16 rasterLine;
    u8 rasterCycle;
    u32 yCounter;
    u16 xCounter;
    u16 vc;
    u16 vcBase;
    u8 rc;
    u8 vmli;

    // Display
    u8 ctrl1;
    u8 ctrl2;
    u8 dy;
    u8 dx;
    bool denBit;
    bool badLine;
    bool displayState;
    bool vblank;
    ScreenGeometry screenGeometry;
    FrameFlipflops frameFF;
    DisplayMode displayMode;
    u8 borderColor;
    u8 bgColor0;
    u8 bgColor1;
    u8 bgColor2;
    u8 bgColor3;
    
    // Memory
    u8 memSelect;
    bool ultimax;
    u16 memoryBankAddr;
    u16 screenMemoryAddr;
    u16 charMemoryAddr;

    // Interrupts
    u16 irqRasterline;
    u8 irr;
    u8 imr;

    // Lightpen
    u8 latchedLPX;
    u8 latchedLPY;
    bool lpLine;
    bool lpIrqHasOccurred;
    
    // Debugging
    
}
VICIIInfo;

Similarly, there is a SpriteInfo struct following the same scheme:

typedef struct
{
    u16 x;
    u8 y;
    bool enabled;
    bool expandX;
    bool expandY;
    bool priority;
    bool multicolor;
    bool ssCollision;
    bool sbCollision;
    u8 color;
    u8 extraColor1;
    u8 extraColor2;
}
SpriteInfo;

The structure is filled inside a function called inspect(). This function is called on a periodic basis when the inspector window is open. It caches all values and when getInfo() is called, the cached values are returned and all GUI elements get updated. In your code, you don't have to use the inspect() / caching mechanism, but the implementation of inspect() shows you where you find all necessary information.

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024 1

thanks dirk ... with your help I got the information now in javascript... as a test I just concatenated the x,y positions of all 8 sprites ... look here I made a wasm_sprite_info method

grafik

when I press the action button

we see the first pair is x,y from the light side, the second pair is the x,y pos from the dark side ...

grafik

from virtualc64web.

dirkwhoffmann avatar dirkwhoffmann commented on May 27, 2024 1

lets beat computer AI from 1984 with our own AI

I was sooooo good at this game back in the day, I didn't need any AI 😎. Surprisingly, this game got harder over time. It must have aged in the storage box like wine... I have no other explanation... πŸ€”

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

I am back ... with a super weapon ... look at this ...

grafik

I coded this super weapon in the last weeks or so , I call it auto defense pilot ... programmed of course in action sequence scriptβ„’ the game enemies have simply no chance ... here as a proof ... you see falcon patrol2

grafik

grafik

In pacman it results very quickly in game over ... πŸ™ˆ it seems to work only in shooters like falcon patrol ... the ghosts might be immune to the defense pilot

@sy2002 what about giana sisters ? Maybe it has to be individually adapted for each game ...πŸ€”

this weapon is already so almighty that I decided to skip beta testing phase and publish it to gh pages so everyone can use it against those mean computer NPC's ...

from virtualc64web.

dirkwhoffmann avatar dirkwhoffmann commented on May 27, 2024

I thought that one is cool, but yours is cooler 😎.

Bildschirmfoto 2020-09-19 um 18 01 42

It looks like a whole new programming language. Is it Turing-complete? πŸ€”

Bildschirmfoto 2020-09-19 um 18 00 39

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

Is it Turing-complete? πŸ€”

no ... it has no state 😳 .. yet ... maybe we should introduce some sort of variables in action sequence script 2 ...

what about this ?

a=1000,loop9{[a]ms,j2fire1,100ms,j2fire0,a-=100}

any advice ?

lets enter a variable in into the action sequence script V1 parser, ...
grafik

no .. I hoped for some selfcoding algorithmπŸ˜… but it seems that it can yet not read from our minds, it complains with syntax error ...

have you already seen the code builder ? when you click on "add" all possible commands are shown, and you can almost click your code without using the keyboard...

grafik

from virtualc64web.

sy2002 avatar sy2002 commented on May 27, 2024

WOW - impressive concept! πŸ‘
But as I am an oldschool gamer, for me this feels a bit like cheating.
What I do understand though is using such a mechanism or example in Blue Max, where you need to do something like "push fire and pull the joystick down" to drop a bomb: On a tablet or a phone this seems impossible and I think this is where this system brings a lot of value (without "cheating" ;-) )

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

@sy2002 yes you are right ... one could write a script that flies the spacecraft automatically out the hangar including opening the hangar door with F7 at β€žraid over moscowβ€œ. Such functions also did exists in elite where you could buy a docking computer.... docking without computer was also very exciting πŸ˜„

from virtualc64web.

dirkwhoffmann avatar dirkwhoffmann commented on May 27, 2024

have you already seen the code builder ?

Very cool. Looks like a retro port of Animator 😎.

no ... it has no state 😳

By looking at the example code, your language seems to have the expressive power of a theoretical language called LOOP. This language is not Turing complete, in contrast to the WHILE language. Exam question: WHILE programs don't have a state, do they? Hmm, OK, maybe we're going off topic here πŸ™„.

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

Ah I get itπŸ™‹πŸ» you want something like this ...

time_between_fire=1000,while(time_between_fire>100) {[time_between_fire]ms,j2fire1,100ms,j2fire0,time_between_fire-=100}

from virtualc64web.

dirkwhoffmann avatar dirkwhoffmann commented on May 27, 2024

Ah I get itπŸ™‹πŸ» you want something like this ...

Indeed, this would make it Turing-complete. But I guess it would be a little over the top for the intended purpose πŸ˜….

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

grafik

added two missing system actions ...

  • restore_last_snapshot

  • swap_joystick

from virtualc64web.

dirkwhoffmann avatar dirkwhoffmann commented on May 27, 2024

Just checked out the latest version. 😎

When the intro screen came up, I was wondering if we still need the emphasized text?

Bildschirmfoto 2020-09-20 um 15 25 56

Maybe it's better to place a "learn more" link (pointing to the OpenRom site) next to the "Install OpenRoms" button. What do you think?

The "automator" is very handy!!! Otherwise, I guess only you would be able to code a proper action button since it's really like a new programming language.

Is it possible to add text typing to the supported actions? I think something like LOAD "$",8 or LOAD "*",,8,1 would be helpful. In VC64mac, I added keyboard shortcuts (CMD-D and CMD-L) for that because the two sequences need to be typed all the time.

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

Just back at my favourite daily social media channel "github" ... πŸ˜… ...

Maybe it's better to place a "learn more" link (pointing to the OpenRom site) next to the "Install OpenRoms" button.

yes you are right ... to much blablabla ... I will change now ...

Is it possible to add text typing to the supported actions? I guess only you would be able to code a proper action ...

Hmm ... it is possible right now to let it type some text... but I see the problems you are pointing me to ...

first problem "token separator":

one could think that the following action script would do ...

l,o,a,d,",$,"😳

Ahhhh πŸ™ˆ the comma is the separator ...

I will look into the code ... πŸ˜… ... luckily it accepts also special key codes ...

so we could write

l,o,a,d,",$,",Comma,8,Comma,1

but this rather does not work ... because of second problem

second problem "timing":

we can not write this in this way because it would press all buttons at once ...
instead we must delay, so it becomes this ...
l,200ms,o,200ms,a,200ms,d,200ms,",200ms,$,200ms,",200ms,Comma,200ms,8,200ms,Comma,200ms,1

but this rather does not work ... because of third problem

third problem keys with shift

" and $ are not recognized as valid key actions by the action script parser yet ...πŸ™Š
It is buggy ...

conclusion:

I guess only you would be able to code a proper action button since it's really like a new programming language.

Oh you are so right ... because it is so buggy ...

to address the first problem ... we could quote the comma but I think we better leave the special key code as it currently is....

the second problem could be adressed if we always default delay lets say 200ms if no delay exists between two commands. If we specify a delay value between two commands then it would overwrite the default ... What do you think ?

the third problem is just an ordinary bug ...

I added keyboard shortcuts (CMD-D and CMD-L)

I thought about that too already ... we could setup a sort of trigger shortcut key for an action button ...

I also think we need to distinct action buttons in gobal action buttons and game specfic action buttons ...

so I think an action button has to be defined by

  • its position on screen
  • its button label
  • a optional shortcut key
  • a boolean flag whether it belongs to the global or game specific list of action buttons

and also I think we should add a template category into the existing add

add->"predefined scripts" ->

  • load"$",8
  • load"*",8,1
  • auto defense pilot

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

I attacked the third problem "keys with shift" first:

now this is a valid action script for load"$",8
Enter,200ms,l,200ms,o,200ms,a,200ms,d,200ms,",200ms,$,200ms,",200ms,Comma,200ms,8,200ms,Enter

grafik

yoda is speaking with me ... he says he feels we should accept something like

ENTER,200ms,'load"$",8',ENTER

and we also got the roms dialog text fixed... looks better now

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

I tried to do what yoda told me ...

ENTER,200ms,'load"$",8',ENTER
the separator char is currently a comma ... that is not optimal ...

problem: the string 'load"$",8' is broken in two tokens

I am looking for an alternative ...

first I thought underscore would be perfect, as this character is not present on C64 keyboard, but I have spotted it on an Amiga keyboard ...

maybe semicolon ; is better

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

or what about two underscores as a separator
ENTER__200ms__'load"$",8'__ENTER

looks nice no ?

or do you like more
ENTER;200ms;'load"$",8';ENTER

or the first character defines the separator
§ENTER§200ms§'load"$",8'§ENTER
.ENTER.200ms.'load"$",8'.ENTER

or we quote comma by a backslash
ENTER,200ms,'load"$"\,8',ENTER

or these two characters as a separator "=>"
ENTER=>200ms=>'load"$",8'=>ENTER

πŸ™„ so much choices ...

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

lets test one of these alternatives ...

here are the opponents:

action sequence script vs. pitfall MOS 6510 code

ready ... steady ... go
grafik

j1right1=>1750ms=>j1fire1=>150ms=>j1fire0=>1600ms=>j1fire1=>400ms=>j1fire0=>j1right0

...
lets press the solve action button πŸ€“
...

after a few seconds ... our script played well and mastered two pitfalls πŸ’ͺ🏾😎

grafik

grafik

what do you think ? Do you like => as a separator?

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

load"$",8 the compact errorproof version 😎

grafik

from virtualc64web.

dirkwhoffmann avatar dirkwhoffmann commented on May 27, 2024

what do you think ? Do you like => as a separator?

Looks much cleaner now. 😎

On a more abstract level, you are adding scripting support to the emulator. In VirtualC64mac, I tried this, too, by adding an AppleScript and JXA interface (in v4.0, I removed both APIs again). Unfortunately, Apple doesn't seem to really care about scripting support any more (AppleScript is from the Middle Ages, JXA is ... I don't know). Of course it would be cool to use some kind of scripting standard instead of a self-designed language, but I don't know if such a standard exists in the web, Windows, or Linux world (as I said, forget about the ridiculous middle-aged stuff provided by Apple).

from virtualc64web.

dirkwhoffmann avatar dirkwhoffmann commented on May 27, 2024

dirk ... we got it ... turing complete ... 😎

Very cool. I like the JavaScript approach more than the self-defined language, because it conforms to a standard.

onAppearance() -> tells us new x,y of a new sprite
onMove() -> tells us new x,y of a sprite
onVanish() -> tells us new x,y of a sprite which was just disabled (probably we have killed it)

It would be possible to add such an API, but the question is in which direction the web version should go. Having such an API would enable us to connect a neural network that learns, e.g., how to play PacMan. This is not a new idea though. Several research groups have done this before. The following video shows how an AI backend learns to play Breakout which is kind of cool:

https://www.youtube.com/watch?v=EfGD2qveGdQ&list=RDEfGD2qveGdQ&start_radio=1&t=60

I think it all comes down to the question what an average user would like do with a web based C64 emulator. Maybe it's better to go in the direction of the C64 scene browser instead of connecting an AI backend? The latter project would be super cool from a research perspective, but the former might attract more users....

from virtualc64web.

sy2002 avatar sy2002 commented on May 27, 2024

Having such an API would enable us to connect a neural network that learns, e.g., how to play PacMan. This is not a new idea though. Several research groups have done this before

Oh - this is done via Reinforcement Learning. A big hobby of mine, but be warned: To train a deep reinforcement learning system to play a computer game, you need to spend about $20k on AWS for computing power only (training the net) - or buy a HUGE machine to put under your desk ;-) So for sure nothing you would do "just like that" ;-)

from virtualc64web.

dirkwhoffmann avatar dirkwhoffmann commented on May 27, 2024

you need to spend about $20k on AWS for computing power only

Hmmm, that is a decent number. So it might be cheaper to hire somebody and copy the trick they used in the first chess playing machine. No?

images

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

Hmm ... artificial intelligence or neuronal nets are very funny ... but I had more in mind a battle of short code fragments / algorithms ... do you both know robocode . it is such a type of game where short programs compete against each other ... see here https://www.youtube.com/watch?v=ZcMLRwu0i-k

what I think of is two short javascript programs, which will battle against each other to see which short program wins ...

the game archon seems very good for that ... in fact the amiga version has a cyborg mode, when activated that mode the computer AI is controlling the hero...

in the c64 version we can play human vs human but control both human players by a javascript action script ... one short program will control the dark and the other the light side ...

chess like movements will be still done by the user ... and the battle will be done by the users "short programs" aka action scripts.

We could define three action buttons one for each short program and one for starting the two programs at once ...

of course the short programs will have to know the own and the opponents position and also the position of the bullet. they could then can track the positions over time (putting them in a javascript array) calculating vectors from that and approximate where to move or to shoot ...

Dirk can you give me an advice how to get the sprite position out of the core ? I think of a wasm_sprite_pos(int sprite_number) returns a string "xpos,ypos"

I think that will be a lot of fun for me ... (don't know whether any other user is knowing about the existance of vc64web ...πŸ˜‚)

it would be a challenge to win against the original game AI as it is damn hard ... and I would not say that it is cheating but rather a quite hard task (at least for me 😬)

another cool game to let two action scripts battle each other would be "international karate"
where we also could set the game to human vs human and give control to the two competing algorithms ... Fortnite dancing moves would be possible too in that game no ?πŸ˜‚

I would like to try this little project first ... and afterwards I like to do the scene browser interface ...

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

first movements ... playing light side with own AI 😍 and finish AI when dark side moves ... that means we can react on the opponent ...

js:
var x=sprite_xpos(1);
var y=sprite_ypos(1);
while(x==sprite_xpos(1) && y==sprite_ypos(1))
{
  console.log('------'+x + ' '+sprite_xpos(1));
  await action("j1right1=>1050ms=>j1right0");
  await action("1000ms");
  await action("j1left1=>50ms=>j1left0");
  await action("1000ms");
  await action("j1fire1=>j1left1=>1000ms=>j1left0=>j1fire0");
  console.log('------'+x + ' '+sprite_xpos(1));
}
alert('finish AI');

grafik

that is so funny !!! I am loving it ... 😍😍😍 Thanks dirk for that toy !!

lets beat computer AI from 1984 with our own AI

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

then we were young and beat it with our fast reacting ... now we are expierienced and we beat it with our brain work ... 😎

I just published the new version to gh-pages

I like the idea of mixing real javascript with action sequence script 😍

await action("j1right1=>1050ms=>j1right0");

thats pretty cool ... the expressive power of javascript and the tailored simplicity to express a simple precisly timed action with action sequence script

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

there was this problem with long running action scripts ....

when we define an action script, lets say

while(true) { await action("A=>500ms"); }

it would run forever ... well more specific until browser reloads vc64web

we have now a better approach for long running AI scripts ...

while(not_stopped(this_id))
{
  await action("A=>500ms");
}

when the user clicks the action button again, while its belonging script is still running ...
not_stopped(this_id) will be false and therefore the while loop will end ...

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

I just tried to use functions ... we can also define functions inside our action script ... that is really nice ...😎

look here ...

js:
var x=sprite_xpos(1);
var y=sprite_ypos(1);

while(not_stopped(this_id))
{
  console.log('------'+x + ' '+sprite_xpos(1));
  await my_move_strategy1(1);  
  await my_aim_and_shoot(1);
  console.log('------'+x + ' '+sprite_xpos(1));
}

async function my_move_strategy1(port)
{ 
  await action(`j${port}right1=>850ms`);
  await action(`j${port}right0=>800ms`);
  await action(`j${port}left1=>450ms`);
  await action(`j${port}left0=>800ms`);
}

async function my_aim_and_shoot(port)
{ 
  await action(`j${port}fire1=>j${port}left1`);
  await action("300ms");
  await action(`j${port}left0=>j${port}fire0`
  );
}

alert('finish AI');

next goal is to write an aim bot... that is whenever the opponent is on the same horizontal or vertical line or 45Β° then shoot automatically ...

I want to be able to move it as human with the joystick but that it aims and shoots automatically ...

from virtualc64web.

dirkwhoffmann avatar dirkwhoffmann commented on May 27, 2024

that is whenever the opponent is on the same horizontal or vertical line or 45Β° then shoot automatically ...

Sounds like a nice addition to the traditional auto fire concept. 😎

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

I just pushed out an vc64web update for the appearance of an action button ... when its script is running now ... its background color changes to red ... when its script finishes the color becomes gray again ... that way we have more sense of what actions are still running ...

see here
grafik

BTW: the AI makes good progress ... you see it active in the picture above ... also 45Β° is working ...

js:

while(not_stopped(this_id))
{
  await aim_and_shoot(1);
  await action("100ms");
}

async function aim_and_shoot(port)
{ 
  var y_light=sprite_ypos(0);
  var y_dark=sprite_ypos(1);
  var x_light=sprite_xpos(0);
  var x_dark=sprite_xpos(1);

  var x_aim=null;
  var y_aim=null;

  if( Math.abs(y_light - y_dark) <15)
  {
   x_aim=x_light-x_dark > 0 ?'left':'right';   
  }
  if( Math.abs(x_light - x_dark) <15)
  {
   y_aim=y_light-y_dark > 0 ?'up':'down';   
  }
  if(x_aim != null || y_aim != null)
  {
   await action(`j${port}fire1`);
   if(x_aim != null)
     await action(`j${port}${x_aim}1`);
   if(y_aim != null)
     await action(`j${port}${y_aim}1`);
   await action("300ms");
   if(x_aim != null)
     await action(`j${port}${x_aim}0`);
   if(y_aim != null)
     await action(`j${port}${y_aim}0`);
   await action(`j${port}fire0`);
  }
}

from virtualc64web.

mithrendal avatar mithrendal commented on May 27, 2024

will be continued in https://github.com/dirkwhoffmann/virtualc64web/issues/60

from virtualc64web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.