dramamine / leftovers-again

Pokemon Showdown - AI/Bot Client Platform
75 stars 21 forks source link

Keep getting Unexpected end of JSON input #13

Closed rokaHakor closed 6 years ago

rokaHakor commented 6 years ago

SyntaxError: Unexpected end of JSON input at JSON.parse () at BattleStore.handleRequest (C:\Users\rokaHakor\Desktop\Folder\node_modules\leftovers-again\src\model\battlestore.js:312:23)

dramamine commented 6 years ago

Hmm. That's some sort of bad request coming through. What sort of stuff are you seeing in the console before that happens? Are you running a server locally and did you connect successfully?

What version do you have installed?

rokaHakor commented 6 years ago
$npm start -- --opponent=randumb

> Joey@0.0.0 start C:\Users\IrmuunTablet\Desktop\Showdown Bot
> node src/app.js "--opponent=randumb"

spawning opponent with path randumb
connecting to: localhost:8000 with name Joey
Got open message from server's websocket.
failed to log in; nick Joey is registered - invalid or no password given.
    Make sure the nickname in your package.json isn't already taken, or
    Register your nickname on http://play.pokemonshowdown.com/ and add
    "nickname" and "password" to your package.json file.

    For now I'm going to add some random digits to your name and try again...
Got open message from server's websocket.
Successfully logged in as Joey5717 (joey5717)
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at BattleStore.handleRequest (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\leftovers-again\src\model\battlestore.js:312:23)
    at BattleStore.handle (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\leftovers-again\src\model\battlestore.js:74:27)
    at Battle.handle (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\leftovers-again\src\battle.js:88:16)
    at Listener.relay (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\leftovers-again\src\listener.js:29:41)
    at WebSocket.handleMessage (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\leftovers-again\src\connection.js:47:20)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at Receiver.ontext (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\ws\lib\WebSocket.js:841:10)
    at C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\ws\lib\Receiver.js:536:18
 ~ cancelling a challenge with larandumbbot2643
child process for randumb exited with code null
We shouldn't go on if our opponent is gone.
 ~ cancelling a challenge with larandumbbot2643

It happens no matter if I git clone https://github.com/dramamine/Pokemon-Showdown.git or https://github.com/zarel/Pokemon-Showdown.git to use as the server.

$ npm start

> pokemon-showdown@0.11.2 start C:\Users\IrmuunTablet\Desktop\New folder\Pokemon-Showdown
> node pokemon-showdown

NEW GLOBAL: global
NEW CHATROOM: lobby
NEW CHATROOM: staff
Worker 1 now listening on 0.0.0.0:8000
Test your server at http://localhost:8000
dramamine commented 6 years ago

Can you make sure you're using 0.11.4 ? "npm install leftovers-again" should get you this version.

rokaHakor commented 6 years ago
IrmuunTablet@IrmuunTablet-PC MINGW64 ~/Desktop/Showdown Bot
$ npm install leftovers-again
npm WARN Joey@0.0.0 No repository field.
npm WARN Joey@0.0.0 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ leftovers-again@0.11.4
added 116 packages and updated 1 package in 11.723s

IrmuunTablet@IrmuunTablet-PC MINGW64 ~/Desktop/Showdown Bot
$ npm start -- --opponent=randumb

> Joey@0.0.0 start C:\Users\IrmuunTablet\Desktop\Showdown Bot
> node src/app.js "--opponent=randumb"

spawning opponent with path randumb
connecting to: localhost:8000 with name Joey
Got open message from server's websocket.
failed to log in; nick Joey is registered - invalid or no password given.
    Make sure the nickname in your package.json isn't already taken, or
    Register your nickname on http://play.pokemonshowdown.com/ and add
    "nickname" and "password" to your package.json file.

    For now I'm going to add some random digits to your name and try again...
Got open message from server's websocket.
Successfully logged in as Joey8900 (joey8900)
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at BattleStore.handleRequest (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\leftovers-again\src\model\battlestore.js:312:23)
    at BattleStore.handle (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\leftovers-again\src\model\battlestore.js:74:27)
    at Battle.handle (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\leftovers-again\src\battle.js:88:16)
    at Listener.relay (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\leftovers-again\src\listener.js:29:41)
    at WebSocket.handleMessage (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\leftovers-again\src\connection.js:47:20)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at Receiver.ontext (C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\ws\lib\WebSocket.js:841:10)
    at C:\Users\IrmuunTablet\Desktop\Showdown Bot\node_modules\ws\lib\Receiver.js:536:18
 ~ cancelling a challenge with larandumbbot6736
child process for randumb exited with code null
We shouldn't go on if our opponent is gone.
 ~ cancelling a challenge with larandumbbot6736

So I opened up Git Bash in the folder I initially installed leftovers-again and used the command "npm install leftovers-again" but nothing changed when using "npm start -- --opponent=randumb "

rokaHakor commented 6 years ago

Also while following the Getting Started guide I saw that the generate.js file and scripts folder was moved to the node_modules/leftovers-again/ folder not node_modules/leftovers-again/src/

dramamine commented 6 years ago

OK, I see what the problem is. I fixed this in the latest version, can you install 0.11.5?

rokaHakor commented 6 years ago

Looks like it is working now however when I have it play against another bot it freezes/stops working after 10 turns. It does nothing after the 10th turn no matter how long I wait.

IrmuunTablet@IrmuunTablet-PC MINGW64 ~/Desktop/Showdown Bot
$ npm start -- stabby --opponent=randumb

> Joey@0.0.0 start C:\Users\IrmuunTablet\Desktop\Showdown Bot
> node src/app.js "stabby" "--opponent=randumb"

spawning opponent with path randumb
connecting to: localhost:8000 with name Joey
Got open message from server's websocket.
failed to log in; nick Joey is registered - invalid or no password given.
    Make sure the nickname in your package.json isn't already taken, or
    Register your nickname on http://play.pokemonshowdown.com/ and add
    "nickname" and "password" to your package.json file.

    For now I'm going to add some random digits to your name and try again...
Got open message from server's websocket.
Successfully logged in as Joey1142 (joey1142)
Match started! joey1142 vs. larandumbbot6746
Your team is: Golduck, Raikou, Trevenant, Ho-Oh, Jynx, Sandslash
             |                    Golduck            |        |        |            Terrakion                  |
    calmmind |       spa+ spd+    Golduck            |        |        |            Terrakion   def- spd-      | closecombat
    psyshock |       spa+ spd+    Golduck            |        | X      |            Mamoswine                  |
             |                                       |      X | X      |            Mamoswine                  |
             |                      Ho-Oh            |      X | X      |            Mamoswine                  | iciclecrash
       roost |                      Ho-Oh            |      X | X      |            Mamoswine                  | iciclecrash
  substitute |                      Ho-Oh            |      X | X      |            Mamoswine                  | iciclecrash
             |                                       |     XX | X      |            Mamoswine                  | iciclecrash
             |                       Jynx            |     XX | X      |            Mamoswine                  | iciclecrash
     icebeam |                       Jynx            |     XX | X      |            Mamoswine                  | iciclecrash

It seems to be working fine when I play vs it.

IrmuunTablet@IrmuunTablet-PC MINGW64 ~/Desktop/Showdown Bot
$ npm start

> Joey@0.0.0 start C:\Users\IrmuunTablet\Desktop\Showdown Bot
> node src/app.js

Your bot is set to accept challenges only - it will not start any battles.
connecting to: localhost:8000 with name Joey
Got open message from server's websocket.
failed to log in; nick Joey is registered - invalid or no password given.
    Make sure the nickname in your package.json isn't already taken, or
    Register your nickname on http://play.pokemonshowdown.com/ and add
    "nickname" and "password" to your package.json file.

    For now I'm going to add some random digits to your name and try again...
Got open message from server's websocket.
Successfully logged in as Joey9420 (joey9420)
Match started! joey9420 vs. satoshioda
Your team is: Musharna, Mudsdale, Oricorio, Tapu Lele, Swampert, Rotom
             |                   Musharna            |        |        |            Leafeon                    |
   moonlight |                   Musharna            |        |        |            Leafeon                    | knockoff
    calmmind |       spa+ spd+   Musharna            |        |        |            Leafeon     atk++          | swordsdance
   moonlight |       spa+ spd+   Musharna            |        |        |            Leafeon     atk++++        | swordsdance
             |                                       |      X |        |            Leafeon     atk++++        | swordsdance
             |                   Mudsdale            |      X |        |            Leafeon     atk++++        | knockoff
             |                                       |     XX |        |            Leafeon     atk++++        | knockoff
             |                 Rotom-Wash            |     XX |        |            Leafeon     atk++++        | leafblade
 thunderbolt |                 Rotom-Wash            |     XX |        |            Leafeon     atk++++        | substitute
             |                                       |    XXX |        |            Leafeon     atk++++        | substitute
             |                   Swampert            |    XXX |        |            Leafeon     atk++++        | leafblade
             |                                       |   XXXX |        |            Leafeon     atk++++        | leafblade
             |                  Tapu Lele            |   XXXX |        |            Leafeon     atk++++        | leafblade
             |                                       |  XXXXX |        |            Leafeon     atk++++        | leafblade
             |                 Oricorio-P            |  XXXXX |        |            Leafeon     atk++++        | leafblade
revelationda |                 Oricorio-P            |  XXXXX |        |            Leafeon     atk++++        | knockoff
satoshioda won.
WINS: X
KOs: 0-6
rokaHakor commented 6 years ago

Thank you so much for making this by the way. I love playing Showdown and learning to program. I want to learn to create machine learning algorithms and I think Pokemon is a great game where machine learning could shine.

dramamine commented 6 years ago

Hmm, I'm not able to repro the "ending after 8 turns" issue, are you getting it consistently? I just ran some battles btwn stabby and randumb, and they went fine WINS: ✓✓✓✓✓X✓✓✓X✓XXX✓ KOs: 6-2 6-5 6-5 6-3 6-2 5-6 6-4 6-5 6-3 2-6 6-5 4-6 2-6 5-6 6-4

To get more debug info, you could run the command with "--loglevel=5" - probably when it crashes out, it'll have some reason for it, like "can't do this move" or something; ex. if a bot tries to do a move but it's not allowed for some reason. I haven't done a lot of testing on Windows so I hope it's not a Windows-specific issue.

I agree with you about machine learning :) hope to see people trying that someday!

rokaHakor commented 6 years ago

Yeah it looks like it is a Windows issue since I'm not having the problem using an Ubuntu vps.