olistic / warriorjs

🏰 An exciting game of programming and Artificial Intelligence
https://warriorjs.com
MIT License
9.41k stars 488 forks source link

This code is wierdly running #263

Closed pickle69420 closed 1 year ago

pickle69420 commented 1 year ago

Sorry for bugging you, but is it just me or is this code supposed to work?

Environment

The warriorjs website.

Steps to reproduce

Use this code on the website level 6 (playTurn function):

if (warrior.feel('backward').isEmpty()) {
    warrior.walk('backward');
} else if (warrior.feel('backward').getUnit().isEnemy()) {
  //Other code (unrelated)
} else if (warrior.feel('backward').getUnit().isBound()) {
  warrior.rescue('backward');
} else if (warrior.feel('backward').isWall()) {
  this.checkedback = true;
}

It will give a wierd error about getUnit being undefined

In the docs it says that if getUnit is undefined then there is nothing hence isEmpty should be true but the else if runs so i dont know what is happening.

If you use this code though:

if (warrior.feel('backward').getUnit() === undefined) {
    warrior.walk('backward');
} else if (warrior.feel('backward').getUnit().isEnemy()) {
  //Other code (unrelated)
} else if (warrior.feel('backward').getUnit().isBound()) {
  warrior.rescue('backward');
} else if (warrior.feel('backward').isWall()) {
  this.checkedback = true;
}

It works but isWall() still returns false so my player keeps bumping into wall.

Expected Behavior

isWall and isEmpty should work...

Actual Behavior

It is wierd (maybe my mistake)

tepinly commented 1 year ago

The game's dead, check the previous issues that have been up for months discussing the same bug with no response whatsoever.

pickle69420 commented 1 year ago

So sad

olistic commented 1 year ago

It will give a wierd error about getUnit being undefined

A space is empty if you can walk there (either no other unit occupying the space or no wall). If there's a wall, isEmpty() will be false but getUnit() will be undefined.

You should check if you have a unit in the space (getUnit() !== undefined) before calling methods on the unit. Or check if there's no wall first.

Closing this now as the above should fix the issue. Please re-open if it doesn't.

olistic commented 1 year ago

The game's dead, check the previous issues that have been up for months discussing the same bug with no response whatsoever.

The game is not dead - I just don't have time to be as active anymore, and I'm relying more in the community members that want to help.