
Warriorjs – An exciting game of programming and artificial intelligence - olistic
https://github.com/olistic/warriorjs
======
crooked-v
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.

~~~
lucideer
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)

------
passivepinetree
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.

~~~
aeorgnoieang
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](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).

~~~
passivepinetree
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).

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

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

------
ibdf
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.

~~~
duxup
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?"

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

[https://github.com/ryanb/ruby-warrior](https://github.com/ryanb/ruby-warrior)

~~~
aeorgnoieang
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.

------
DDR0
`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.)

~~~
olistic
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](https://github.com/olistic/warriorjs/issues/69)

------
hiimshort
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.

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

~~~
chrisweekly
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`

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

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

~~~
danielvinson
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.

~~~
pdav
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?

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

------
piqalq
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?

~~~
kroltan
There are many polyglot "code games".

Off the top of my head: [http://codingame.com/](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/](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.

~~~
brute
You are probably thinking of
[http://robocode.sourceforge.net/](http://robocode.sourceforge.net/)

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

------
antileet
Similar JavaScript programming game running in the browser -
[http://jswarrior.fusioncharts.com/](http://jswarrior.fusioncharts.com/)

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

------
DEinspanjer
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?

~~~
olistic
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).

~~~
DEinspanjer
Yep, I'm running Node v10.1.0

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

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

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

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

~~~
aeorgnoieang
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?

~~~
partycoder
It was apparently submitted by the author.

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

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

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

