olistic / warriorjs Goto Github PK
View Code? Open in Web Editor NEW🏰 An exciting game of programming and Artificial Intelligence
Home Page: https://warriorjs.com
License: MIT License
🏰 An exciting game of programming and Artificial Intelligence
Home Page: https://warriorjs.com
License: MIT License
When I try and run warriorjs on mac 10.10.3 with bash version 3.2 im getting this error
$ warriorjs
Welcome to WarriorJS
undefined:1
1���l"{-jY^��]�ب����]��ߵ����^��}uا��ڦ�覸����L{ڮ&�������+a1���l{h���L������
^
SyntaxError: Unexpected token �
at Object.parse (native)
at Function.decode (/usr/local/lib/node_modules/warriorjs/lib/Profile.js:313:19)
at Function.load (/usr/local/lib/node_modules/warriorjs/lib/Profile.js:318:57)
at Game.start (/usr/local/lib/node_modules/warriorjs/lib/Game.js:56:46)
at Runner.run (/usr/local/lib/node_modules/warriorjs/lib/Runner.js:42:18)
at Object.<anonymous> (/usr/local/lib/node_modules/warriorjs/bin/warriorjs:6:8)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
Sometimes you just want to see the outcome of the play (whether you passed the level or not) and not the play log. Running warriorjs --silent
should make that possible. Example:
$ warriorjs --silent
Welcome to WarriorJS
? Choose a profile: Spartacus - beginner - level 1 - score 0
Success! You have found the stairs.
Warrior Score: 0
Time Bonus: 8
Clear Bonus: 2
Total Score: 10
? Would you like to continue on to the next level? (y/N)
Note: I manually replaced npm
with yarn
in the command.
@warriorjs/core/lib/PlayerLoader.js
for demonstration purposes:-this.sandbox = vm.createContext();
+this.sandbox = vm.createContext({ console });
console.log(warrior.feel().floor);
in a level that has warrior.feel()
available.floor
should not be accesible
The following gets logged into the console:
Floor {
width: 7,
height: 1,
stairsLocation: [ 6, 0 ],
units:
[ Warrior {
name: 'mrCyborg',
character: '@',
maxHealth: 20,
captive: false,
abilities: [Map],
effects: Map {},
health: 20,
position: [Position],
bound: false,
score: 0,
turn: [Turn],
player: [Player] },
Unit {
name: 'Thick Sludge',
character: 'S',
maxHealth: 24,
captive: false,
abilities: [Map],
effects: Map {},
health: 24,
position: [Position],
bound: false,
score: 0,
turn: null,
playTurn: [Function: playTurn] },
Unit {
name: 'Archer',
character: 'a',
maxHealth: 7,
captive: false,
abilities: [Map],
effects: Map {},
health: 7,
position: [Position],
bound: false,
score: 0,
turn: null,
playTurn: [Function: playTurn] },
Unit {
name: 'Thick Sludge',
character: 'S',
maxHealth: 24,
captive: false,
abilities: [Map],
effects: Map {},
health: 24,
position: [Position],
bound: false,
score: 0,
turn: null,
playTurn: [Function: playTurn] } ],
warrior:
Warrior {
name: 'mrCyborg',
character: '@',
maxHealth: 20,
captive: false,
abilities:
Map {
'walk' => [Object],
'attack' => [Object],
'feel' => [Object],
'health' => [Object],
'rest' => [Object] },
effects: Map {},
health: 20,
position: Position { floor: [Circular], location: [Array], orientation:'east' },
bound: false,
score: 0,
turn: Turn { action: null },
player: Player { turn: 1, history: [Object], warrior: [Turn] } } }
I didn't have node.js installed on my machine, so obviously the command to install the package didn't work and I spent a good amount of time to finally understand that I needed node.js. I suggest adding a note to the installation notes about having node.js installed.
Thanks.
With a local install Flo@Florians-MacBook-Pro-3:~/Desktop/warriorjs$ sudo npm install warriorjs
on node v0.10.33, I get the following error:
Flo@Florians-MacBook-Pro-3:~/Desktop/warriorjs/node_modules/warriorjs/bin$ ./warriorjs
Welcome to WarriorJS
[1] beginner
[2] intermediate
Choose tower by typing the number: 1
Enter a name for your warrior: chap
/Users/Flo/Desktop/warriorjs/node_modules/warriorjs/node_modules/fs-extra/lib/mkdir.js:87
throw err0
^
Error: ENOTDIR, not a directory '/Users/Flo/Desktop/warriorjs/node_modules/warriorjs/bin/warriorjs/chap-beginner'
at Object.fs.mkdirSync (evalmachine.<anonymous>:653:18)
at Object.mkdirsSync (/Users/Flo/Desktop/warriorjs/node_modules/warriorjs/node_modules/fs-extra/lib/mkdir.js:70:9)
at PlayerGenerator.generate (/Users/Flo/Desktop/warriorjs/node_modules/warriorjs/lib/PlayerGenerator.js:52:32)
at Level.generatePlayerFiles (/Users/Flo/Desktop/warriorjs/node_modules/warriorjs/lib/Level.js:161:46)
at Game.prepareNextLevel (/Users/Flo/Desktop/warriorjs/node_modules/warriorjs/lib/Game.js:174:27)
at Game.playNormalMode (/Users/Flo/Desktop/warriorjs/node_modules/warriorjs/lib/Game.js:117:16)
at Game.start (/Users/Flo/Desktop/warriorjs/node_modules/warriorjs/lib/Game.js:70:14)
at Runner.run (/Users/Flo/Desktop/warriorjs/node_modules/warriorjs/lib/Runner.js:42:18)
at Object.<anonymous> (/Users/Flo/Desktop/warriorjs/node_modules/warriorjs/bin/warriorjs:6:8)
at Module._coFlo@Florians-MacBook-Pro-3:~/Desktop/warriorjs/node_modules/warriorjs/bin$
At Level 8 you start right on top of the ticking captive
(Captive on 5/0)
(Warrior on 5/0)
Either the warrior or the captive should be on 0/0 (i think the warrior should be there)
System:
OS: Windows 10
CPU: x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 8.48 GB / 15.86 GB
Binaries:
Yarn: 1.5.1 - ~\AppData\Roaming\npm\yarn.CMD
npm: 5.7.1 - C:\Program Files\nodejs\npm.CMD
Virtualization:
Docker: 18.03.0 - C:\Program Files\Docker\Docker\Resources\bin\docker.EXE
IDEs:
VSCode: 1.23.1 - C:\Program Files\Microsoft VS Code\bin\code.CMD
Languages:
Bash: 4.4.12 - C:\Program Files\Git\usr\bin\bash.EXE
Python: 2.7.14 - /c/Python27/python
Browsers:
Edge: 42.17666.1000.0
Internet Explorer: 11.0.17666.1000
npm i -g warriorjs
warriorjs
(follow default config)Player.js
and add a console.log('hello')
statement in the playTurn
methodplayTurn () { console.log('Hello World'); }
warriorjs
(select your character to run)All console
statements should be displayed in the output (or at least logged to a file).
No console
statements display.
So far I think the issue comes from running in a new vm context. That call happens here: https://github.com/olistic/warriorjs/blob/master/packages/warriorjs-core/src/PlayerLoader.js#L23
And finally, this is a really cool project. Thanks to everyone for the great work so far!
The objects passed to the Player (Turn
as an argument of the playTurn
method and Space
as a result of using senses) should be proxy objects, containing only the methods the player is allowed to use.
I invoked warriorjs
from ~
on OSX Yosemite and it complained because I already had a .profile
file.
Welcome to WarriorJS
/opt/some/folder/node_modules/warriorjs/lib/Profile.js:316
throw new Error('Invalid .profile file. Try changing the directory und
^
Error: Invalid .profile file. Try changing the directory under you are running warriorjs.
at Function.decode (/opt/some/folder/v0.10.38/lib/node_modules/warriorjs/lib/Profile.js:316:15)
at Function.load (/opt/some/folder/nvm/v0.10.38/lib/node_modules/warriorjs/lib/Profile.js:322:57)
at Game.start (...Game.js:56:46)
at Runner.run (...Runner.js:42:18)
at Object.<anonymous> (...warriorjs:6:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
Ok, so I didn't completely follow the directions and did a git clone of warriorjs and that means I probably have work in progress code. Admitted :)
Now that we are on the same page, I've worked through differences easily enough in the code, until I got to the part where I have to start looking for wizards (level 8). Problem is, seems in the next version look() is going to return a list of objects instead of a string representation of what's in the direction your "looking"
Any pointers, I've tried inspecting the result but its a bit less than conducive to understanding.
I can post my code, but I doubt it will change anything :)
Really like this concept. As someone looking to use more ES6 goodness in my code, it'd be nice to get some ES6 based hints for each level that'll help people like me start to use more ES6 concepts over ES5.
Level READMEs in markdown format could be great if you're using some kind of markdown processor to read them. If you're not planning on doing so, having the markdown syntax laying around creates noise. Running warriorjs --no-markdown
should take care of that, and output to README.txt
instead of README.md
.
Ticking captives exists even if the timer has run out.
A negative effect could potentially kill a unit. We need to check if the unit is still alive after executing the effects and return early if the unit died. Example: a "poisoned" effect (it doesn't exist, at least yet) that damages the unit turn by turn.
The below code is not efficient. Please use the map function once
addAbilities(abilities = []) { abilities.forEach((newAbility) => { if (this.abilities.map(ability => ability.name).indexOf(newAbility.name) === -1) { this.abilities.push(newAbility); } });
It would be nice if we supported multiple languages, which can be done via Docusaurus integration with Crowdin.
After successfully installing warriorjs with:
npm install -g warriorjs
i'm getting
-bash: warriorjs: command not found
This isn't the first global module that I install btw (:
I started warriorjs in intermediate difficulty and am stuck in level 4 when trying to free the two captives.
let captiveSpace = warrior.listen().find(space => space.isCaptive());
console.log(captiveSpace);
console.log(warrior.directionOf(captiveSpace));
The last line in the test code above fails with
TypeError: Object [object Object] has no method 'getLocation'
at Position.getDirectionOf (/usr/lib/node_modules/warriorjs/lib/Position.js:107:39)
If I read the source correctly, the listen()
call converts the spaces to "player objects" before returning them, which drops the method getLocation()
. But getLocation()
is needed for warrior.directionOf()
.
If I'm just using it wrong, please consider making the level's README a bit more clear instead.
I found myself needing to determine when my warrior changed states, and realized there is no api for showing that in the flow of the simulation.
It would be nice if there was an ability that showed a message like: thinks "Hello World!" in line with the turns, just like any other action.
I don't want to see all de moves, I just want to see if it succed or fails.
I think you should create a page where you list all the solutions for each level.
In your readme you say "This is a game designed to teach JavaScript and artificial intelligence in a fun, interactive way."
Since this game is about learning I think you should be able to learn from your mistakes. I found myself stuck on a level and didn't know what to do.
I think being able to view the solution after you tried your best to solve it yourself helps you create better code, you gain good insight into how the code should look and with this example in mind you can go ahead and tackle the next level.
You can go about this a couple of different ways, you can for instance create something like a wiki page where you just list them all (this can also be right here on github (just a bunch of files)).
You can also include the solution inside the level's folder, or include a folder with solutions on the users side of things.
I really hope you'll add this feature in the future! Awesome project!
Enable search for the documentation using Algolia DocSearch as described here.
Hey, just found your game through Twitter, neat idea! Wish I'd though of it...
Anyways, great to see it's ES6 ready. However, instead of using a global variable, the player code should probably export the Player
class instead.
Otherwise, keep up the good work!
I know this is supposed to make you learn... But I have been trying for 6 hours and I still cannot get past this stage. So I figured this is possibly the best my brain can do with the limited experience I have with javascript.
Firstly, I don't know what is the attack range of the wizards.
Secondly, I also don't know how to use the .look() ability.
But after fiddling with them a bit, I realized that the look ability actually returns an array. However there's no way to use that unless you put what is returned into another variable to be read as an array.
And after doing that, I am guessing I would have to loop through the items or something and I did that but my warrior either does nothing, or walks forward, saves captive, walks forward, attacks the wizard, rests and gets killed by the second wizard. I have tried to check if the position of the wizard is at least 3 spots away from my warrior and to move backward if it isn't but because of the second wizard, the for loop just uses the second wizard to account for position...
so how do I solve this..? Am I overthinking this?!
Right now, you earn points no matter if you kill a hostile or a friendly unit. Check if the unit is hostile before awarding the points and subtract them instead if the unit was friendly.
It could be a good addition to see the current score of the warrior in the play log. Example:
--------------------------------------- turn 005 ---------------------------------------
♥ 14
⬥ 0
╔════════╗
║ @s >║
╚════════╝
> Spartacus attacks forward and hits Sludge
> Sludge takes 5 damage, 2 health power left
> Sludge attacks forward and hits Spartacus
> Spartacus takes 3 damage, 14 health power left
--------------------------------------- turn 006 ---------------------------------------
♥ 14
⬥ 12
╔════════╗
║ @ >║
╚════════╝
> Spartacus attacks forward and hits Sludge
> Sludge takes 5 damage, 0 health power left
> Sludge dies
> Spartacus earns 12 points
--------------------------------------- turn 007 ---------------------------------------
♥ 14
⬥ 12
╔════════╗
║ @ >║
╚════════╝
> Spartacus walks forward
To make that possible, the core will need to include the unit's score along with the currently included fields.
I've tried installing this but can't get it to work:
mkdir javascript
cd javascript
npm install -g warriorjs
But then running it doesn't recognize the command:
$ warriorjs
> -bash: warriorjs: command not found
Hi,
I would like to get the information of the type of the enemy and not just if an enemy is at the certain unit.
This will make it easier to design a strategy.
Also in level 7 it was a bit odd because i was in the middle of two enemies and did not "know" (mean without looking at the README) if the archer was on the right or left side. This is a bit odd.
Thanks,
David
I ran npm install -g warriorjs
and then warriorjs
and then nothing.
complained it couldn't find 'yargs', installed that, then i didn't have 'glob', installed that. Now it all works fine.. I think this is a dependency issue? I'm still kind of green to how npm does dependency management. Cheers!
Units are "hostile" or "friendly", instead of "enemy" or "captive". This gives greater flexibility.
With this change:
hostile
parameter that defaults to true
instead of the current captive
parameter..isEnemy()
is removed in favor of a new and simplified method .isHostile()
.
.isHostile()
calls unit.isHostile()
(also new) under the hood..isHostile()
still returns false
if the unit is bound..isCaptive()
is removed in favor of a new method .isFriendly()
.Docs and official levels tips like this one will need update as well.
UPDATE: Let's also pass a bound
parameter that defaults to false
to the Unit's constructor, and set it to true
in the Captive
unit definition.
Is import not supported in Player.js?
import { MyClass } from './class.js'
results in Cannot read property playTurn of null
Have anyone found a workaround? Great game btw!
With the current warrior.listen() you can forget about all the other senses.
Just call warrior.listen() once at the beginning of the Level and you never have to use any senses again.
In my Opinion only the ticking captives/enemys? should be returned by listen. Other units remain silent.
This way you have to Look arround.
But but how about you can only determin the base class of the enemy with warrior.look()
(Ranged/Melee/Captive)
This way you have to use all senses to determine the right Behavior.
New Senses in summary
listen - only return tickings
look - only return baseclass
feel - return detail Information
2
When running warriorjs I get the following error:
thom@thom-laptop:~/Documents]~% warriorjs
module.js:327
throw err;
^
Error: Cannot find module '../../constants/directions'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/thom/.nvm/versions/node/v4.4.4/lib/node_modules/warriorjs/node_modules/warriorjs-engine/lib/abilities/actions/Attack.js:10:19)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/thom/.nvm/versions/node/v4.4.4/lib/node_modules/warriorjs/node_modules/warriorjs-engine/lib/LevelLoader.js:10:15)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
When I check the constants location I find the following:
[thom@thom-laptop:lib/constants]~% l (v0.29.0)
total 108K
-rw-rw-r-- 1 thom thom 2,4K apr 8 06:18 Abilities.js
-rw-rw-r-- 1 thom thom 335 nov 15 2015 Actions.js
-rw-rw-r-- 1 thom thom 560 apr 10 20:12 Directions.js
-rw-rw-r-- 1 thom thom 308 apr 10 20:12 eventTypes.js
-rw-rw-r-- 1 thom thom 171 apr 2 00:57 logEvents.js
-rw-rw-r-- 1 thom thom 406 apr 8 06:18 RelativeDirections.js
-rw-rw-r-- 1 thom thom 335 nov 15 2015 Senses.js
-rw-rw-r-- 1 thom thom 998 apr 8 06:18 Units.js
-rw-rw-r-- 1 thom thom 303 nov 16 2015 UnitTypes.js
It seems warriorjs is looking for "directions.js" (lowercase) while the file name is "Directions.js"
When I symlink Directions.js to directions.js things seem to work fine
Hi,
how can I run some sort of config code to set some defaults on the begging of every level? When I run levels separately, I simple check if var is undefined however if I play an epic mode, it runs the config only once in 1st level.
Thanks
When an error occurs, it would be super useful to know what line it occurred on etc.
Love the game!
Great program, but I am having a hard time getting past level four on beginner mode. Could you please help?
Hi guys. Not so much an issue as a question.
What IDE do you recommend I work from to get started on this project? I am completely new to JS and I thought that playing this game would be a great way to get started.
I am currently using Visual Studio but it is not great with JS. IntelliSense doesn't work nicely and I can't compile to check for syntax errors. I have managed to make it to Beginner Level 7 so far with this, but I was thinking that there must be an easier way to do this?
Thanks so much for the game, I am really enjoying it so far and I think I am starting to get the hang of JS.
It would be great if there were an option to make the speed of the terminal output configurable.
I couldn't find anything in the readme and it seems like the delay is hardcoded at the moment.
Any chance to make this configurable?
When killing an enemy, you earn points equal to that enemy's max health, but when rescuing a captive you earn the amount of points defined by the rescue ability.
An optional reward
field could be a good addition to the Unit class:
The last bullet is what adds greater flexibility to the game and to the Tower makers.
The rescue ability awards a fixed amount of points for rescuing a captive unit. With the addition of the reward field, it should give those points now instead of the fixed amount.
Blockers: #60
It seems that rest() method doesn't update health in current round;
if my current health is 15 and I'm doing
console.log(warrior.health());
warrior.rest();
console.log(warrior.health());
I'm getting both console logs 15.
Is this intended or am i missing something?
By default, Docusaurus hides the header icon on small devices (<= 375px width) because there's still a title to show. In WarriorJS, we have disabled the title in the header so we shouldn't hide the icon.
Not sure if this is possible or not. Is it possible to get the space where the warrior is currently standing?
I might want to use that location later on.
I have an idea how to emulate this: when warrior.walk() -> let comingFrom =
opposite of current walking direction (if walking right, save left, if walking forward, save backward) -> next turn: save warrior.feel(comingFrom)
for later use, as this is the space the warrior came from.
Have you seen or considered using https://github.com/qiao/PathFinding.js?
here is my code
class Player {
playTurn(warrior) {
// Cool code goes here
if (warrior.feel().isEnemy()) {
warrior.attack();
} else {
warrior.walk();
}
}
}
The system told me " warrior.feel is not a function" after running command "warriorjs" , so should i build a class "warrior"?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.