Hacker News new | past | comments | ask | show | jobs | submit login
Warriorjs – An exciting game of programming and artificial intelligence (github.com/olistic)
293 points by olistic on May 11, 2018 | hide | past | favorite | 52 comments



This is interesting. Though, for my part, rather than...

    class Player {
      playTurn(warrior) {
        warrior.walk();

        ...
      }
    }
...I would much rather have something like...

    import { Warrior } from '@warriorjs/cli';

    class MyWarrior extends Warrior {
      playTurn() {
        this.walk();

        ...
      }
    }
...or...

  function playTurn(warrior) {
    warrior.walk();

    ...
  }
The current style is a weird mix of functional and object-oriented handling.


In this particular example, I don't see why. Player and Warrior are conceptually different entities: one is the player of the game, having properties and methods related to controlling gameplay (e.g. a player might play as alternate warriors at different times), the latter is the avatar, having properties and methods related to that fictional characters attributes within the world of the game.

The differences in purpose of the two entities aren't really anything to do with fp vs oop; I don't see what's fp-ish about the first example, and your last example is potentially a weird mix of fp and oop (depending on what "warrior" is, and I can't figure out what use it would be in that context if it wasn't an object with encapsulated methods)


It would be awesome if there was a way to gain information about your enemies. For example, sometimes (when facing a sludge), it's better to run away, heal, and come back to finish it off at full health. When facing an archer, it's often better to power through and kill it before healing. There's no programmatic way to know which enemy is attacking your warrior, so I'm often finding myself writing custom, non-reusable code for a specific level, which isn't great.


I stopped playing at the level where this became critical for exactly this reason. My warrior presumably has eyes, so why can she not tell the difference between a sludge and an archer? If the goal was ultimately to write a player that could succeed in any arbitrary level ("Epic Mode"), I did not feel like I could accomplish that without being able to know what I was up against. If I have to hardcode decisions based on known levels anyway... might as well just hardcode exact instructions on which actions to take based on a counter. But at that point, it doesn't really feel like programming an artifical intelligence anymore.


Hello, I'm sorry you feel that way. I think that being able to determine what enemies your warrior is facing is something valuable. However, it's possible to succeed in epic mode (and get a perfect score) without hard-coding any instruction.


Can't you infer what enemy you're facing based on the damage they do to you?

In the original, [ruby-warrior](https://github.com/ryanb/ruby-warrior), you can `listen` (at some point) to get an array of occupied spaces and then you can check if a space contains an enemy. If you're not immediately adjacent to an enemy but your warrior is taking damage you can infer you're being attacked by an archer (or another enemy with a ranged attack).


This is a really good idea that somehow I totally missed. I stopped playing at a level where this became important (as @elefantastisch noted above), but now I kind of want to pick it back up again. It's not guaranteed to work (different enemies might deal the same amounts of damage), but maybe location could help in those cases (i.e., if my warrior is being dealt a certain amount of damage and the space in front and behind the warrior is empty, one could infer the enemy is an archer).


Something for basic enemy assessment would allow for more tactical action, though. For example, checking armor and weapon types to switch between your own equipment (hammers vs heavy armor, swords vs cloth armor, spears vs spearmen or beasts with tough hides) - or putting together different signs to decide if an unarmored enemy is a wizard or a thief.


Screeps does that, and it doesn't have "classes" per se, but modular bodies... so you can look at an enemy and see that they have some HEAL body parts, so you know they are a healer. You can even calculate how much healing per turn they can do to influence your fight or flight, or target priority decisions (you have multiple units, after all).


Looking at the code you could do getCharacter() for a Space returned by look()/listen()/feel() to figure out what type of enemy it is: https://github.com/olistic/warriorjs/blob/master/packages/wa...


This is somewhat similar to Screeps (https://screeps.com/) - RTS MMO that you code in Javascript.


What a great game. I really should get back into it...


Perfect! A game that I can play at work while not working but looking like i'm working. Rename warrior to latest project name and boom, I code all day.

But in all seriousness, the floor map idea is pretty neat.


Just be sure it doesn't leak into work code.

"Dude about what you pushed yesterday.... what is this swordOfDestiny function you keep using on customer records?"


There is also a Ruby Warrior project if someone want to do this in Ruby.

https://github.com/ryanb/ruby-warrior


At the bottom of the project's README:

> This project was born as a port of ruby-warrior. Credits for the original idea go to Ryan Bates.

I was sure of it based on how (almost exactly) similar this was.


Indeed! This is how I learned Ruby several years ago, fun project.


`console.log()` does nothing. `debugger` does nothing. How am I supposed to figure out why 'this.isTakingDamage' function isn't working? Just look at it real hard?

I'm not some sort of deity who can just write perfect javascript the first time around.

On a side note, running with `entr -p warriorjs --time 0.4 <<< Player.js` is quite convenient. (Run the warrior through the level on save of file.)


Hello DDR0. You're right, you're not a deity, you're a person. Same as people on the other side of the project, who can't just write a perfect game the first time around.

If you're interested in proposing a solution for the issue you describe, there's already people discussing it here: https://github.com/olistic/warriorjs/issues/69


I stumbled across this yesterday and had a great time implementing all sorts of interactions for my character. If you're the kind of person who enjoys puzzles or problem solving, this is definitely the game for you.


Looks really fun, but is there any way I can play online without having to set up a whole environment for this?


Thanks, and good you ask. The online version is in the works, going to be available soon at warriorjs.com. Follow @warrior_js on Twitter to be notified about the release.


If you're reluctant to install a global package just to try this, any recent Node includes npm5+, which in turn comes with `npx`, enabling:

`npx @warriorjs/cli`


While I doubt this applies to others, my issue here is that my primary work computer is running Windows.


I just ran this on windows, what's the problem you had with it?


Its more of a large inconvenience - I don't develop on my computer, I write all code on servers in my company's cloud. My choice would be to either clone this onto company hardware in the cloud or install node and the associated tools on my desktop.


Is there a particular reason that playing this game on your employer's hardware (and, presumably, on your employer's time) is better than installing it on your computer and playing it at home?


I think they are explaining why they would rather play online; those are the two options and both not preferable.


> and, presumably, on your employer's time

Lunch at your desk and "nothing to do if nothing breaks" server-monitoring shifts are both common, and that's just in the tech world.


Seems like a good use-case for a linux VM? I tend to use VMs for things it's clear shouldn't really be installed on my workstation.


I do agree, and this is how I evaluate a lot of tools, but wouldn't it be easier just to have a web page? I'm not saying that I can't use this, I'm saying that it would be far more convenient for me (and likely many others).


Node on Windows has worked servicably for a long time.


Use any web ide like Codenvy.com and you have it at least seperated from your computer


I’ve wondered, why are these types of games, such as Screeps or WarriorJS only ever made to be played with JS. Why not Python or Go or Assembly?


There are many polyglot "code games".

Off the top of my head: http://codingame.com/ - They support a lot of languages, even Rust!

I also remember an old Java application where you would write AIs for dueling bots, but I don't recall the name.

The folks at https://codegolf.stackexchange.com/ also host several games like that, more often than not competitively, however, and not open-ended or "singleplayer" games. Most accept any language that can take stdin and print stdout.


You are probably thinking of http://robocode.sourceforge.net/

I played this like 17 years ago and to my most pleasant surprise, the project is still alive.


> I also remember an old Java application where you would write AIs for dueling bots, but I don't recall the name.

Sounds like Robocode.


This one's based on [ruby-warrior](https://github.com/ryanb/ruby-warrior).

I'm sure there are other ports for other languages too. I'm pretty sure there's a Python one for one.


https://en.wikipedia.org/wiki/Core_War

Probably because if it's going to be in the browser, they have to do a large chunk of the work in JS anyways

and of course, everything is JS these days


Everybody and their cousin can write basic javascript, especially for these kinds of pretty easy cases.

If you know python and had never written JS before, you could probably still play this with a bit of trial and error.


Why would you use those over the ubiquitous language?


Similar JavaScript programming game running in the browser - http://jswarrior.fusioncharts.com/

Me and a friend built this in 2013, built on top of ideas from the original ruby-warrior.


Did anyone else have an issue where when installing and running warriorjs for the first time, the player.js file doesn't have any template code in it?


I found this to be an issue with Node 10, did you happen to be running that version? It was already fixed and a new version will be released soon (meanwhile you should be able to play with Node 8).


Yep, I'm running Node v10.1.0

I worked around it by just copying the class as described in the website.


Would be fun if there were code-golf scoring: Player.playTurn.toString().length ️


Interesting idea that I'll definitely keep in mind for the online version. Thanks!


Should have "Show HN" in the title in my opinion.


Why's that? Was this submitted by the author or a contributor?

I couldn't find anything about when "Show HN" is expected in submission titles. What're the rules or conventions?


It was apparently submitted by the author.


npm ERR! Please try running this command again as root/Administrator.

-> So, it is for god players already...


Really cool project idea. The post submission title seems kind of click-baity though.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: