Bam4d / python-microRTS

A python client library for microRTS.
Apache License 2.0
18 stars 5 forks source link

Instructions on starting microRTS #2

Open douglasrizzo opened 4 years ago

douglasrizzo commented 4 years ago

After starting my own agent, which inherits from pyrts.server.Server, how should I start microRTS?

I changed launch_mode=SERVER and AI1=ai.socket.SocketAI in config.properties and started rts.units.MicroRTS, but I get a java.net.BindException: Address already in use from MicroRTS.

douglasrizzo commented 4 years ago

I have figured it out. I should start MicroRTS in client mode, not server mode.

douglasrizzo commented 4 years ago

OK, it seems like I need some help after all. I tried running the examples and then starting MicroRTS in Client mode. This is the output of running one of the python-microRTS examples (I applied the pull request which fixes a bug after gameover):

$ python Code/python-microRTS/examples/random_actions.py
server is running
DEBUG:RTSServer:Socket created
DEBUG:RTSServer:Socket bind complete
DEBUG:RTSServer:Socket now listening
DEBUG:RTSServer:<socket.socket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 9898), raddr=('127.0.0.1', 45626)>
DEBUG:RTSServer:('127.0.0.1', 45626)
DEBUG:RTSServer:Connected with 127.0.0.1:45626
DEBUG:RTSServer:Message: budget 100 0

DEBUG:RTSServer:budget 100 0
DEBUG:RTSServer:Message: utt
{"moveConflictResolutionStrategy":1,"unitTypes":[{"ID":0, "name":"Resource", "cost":1, "hp":1, "minDamage":1, "maxDamage":1, "attackRange":1, "produceTime":10, "moveTime":10, "attackTime":10, "harvestTime":10, "returnTime":10, "harvestAmount":1, "sightRadius":0, "isResource":true, "isStockpile":false, "canHarvest":false, "canMove":false, "canAttack":false, "produces":[], "producedBy":[]}, {"ID":1, "name":"Base", "cost":10, "hp":10, "minDamage":1, "maxDamage":1, "attackRange":1, "produceTime":200, "moveTime":10, "attackTime":10, "harvestTime":10, "returnTime":10, "harvestAmount":1, "sightRadius":5, "isResource":false, "isStockpile":true, "canHarvest":false, "canMove":false, "canAttack":false, "produces":["Worker"], "producedBy":["Worker"]}, {"ID":2, "name":"Barracks", "cost":5, "hp":4, "minDamage":1, "maxDamage":1, "attackRange":1, "produceTime":100, "moveTime":10, "attackTime":10, "harvestTime":10, "returnTime":10, "harvestAmount":1, "sightRadius":3, "isResource":false, "isStockpile":false, "canHarvest":false, "canMove":false, "canAttack":false, "produces":["Light", "Heavy", "Ranged"], "producedBy":["Worker"]}, {"ID":3, "name":"Worker", "cost":1, "hp":1, "minDamage":1, "maxDamage":1, "attackRange":1, "produceTime":50, "moveTime":10, "attackTime":5, "harvestTime":20, "returnTime":10, "harvestAmount":1, "sightRadius":3, "isResource":false, "isStockpile":false, "canHarvest":true, "canMove":true, "canAttack":true, "produces":["Base", "Barracks"], "producedBy":["
Base"]}, {"ID":4, "name":"Light", "cost":2, "hp":4, "minDamage":2, "maxDamage":2, "attackRange":1, "produceTime":80, "moveTime":8, "attackTime":5, "harvestTime":10, "returnTime":10, "harvestAmount":1, "sightRadius":2, "isResource":false, "isStockpile":false, "canHarvest":false, "canMove":true, "canAttack":true, "produces":[], "producedBy":["Barracks"]}, {"ID":5, "name":"Heavy", "cost":3, "hp":8, "minDamage":4, "maxDamage":4, "attackRange":1, "produceTime":120, "moveTime":10, "attackTime":5, "harvestTime":10, "returnTime":10, "harvestAmount":1, "sightRadius":2, "isResource":false, "isStockpile":false, "canHarvest":false, "canMove":true, "canAttack":true, "produces":[], "producedBy":["Barracks"]}, {"ID":6, "name":"Ranged", "cost":2, "hp":1, "minDamage":1, "maxDamage":1, "attackRange":3, "produceTime":100, "moveTime":10, "attackTime":5, "harvestTime":10, "returnTime":10, "harvestAmount":1, "sightRadius":3, "isResource":false, "isStockpile":false, "canHarvest":false, "canMove":true, "canAttack":true, "produces":[], "producedBy":["Barracks"]}]}

DEBUG:RTSServer:utt
DEBUG:RTSServer:Message: budget 100 0

DEBUG:RTSServer:budget 100 0
DEBUG:RTSServer:Game has ended

This is the output of running MicroRTS in client mode:

----------Game Settings----------
Running as Server: CLIENT
Server Address: 127.0.0.1
Server Port: 9898
Serialization Type: 2
Map Location: maps/16x16/basesWorkers16x16.xml
Max Cycles: 5000
Partially Observable: false
Rules Version: 2
Conflict Policy: 1
AI1: ai.abstraction.WorkerRush
AI2: ai.RandomBiasedAI
------------------------------------------------
java.lang.NullPointerException: string is null
    at com.eclipsesource.json.Json.parse(Json.java:292)
    at rts.PlayerAction.fromJSON(PlayerAction.java:356)
    at ai.socket.SocketAI.getAction(SocketAI.java:196)
    at rts.RemoteGame.run(RemoteGame.java:63)
    at rts.MicroRTS.startClient(MicroRTS.java:63)
    at rts.MicroRTS.main(MicroRTS.java:36)

The problem is that MicroRTS receives an empty JSON (in this line, the value of the JSON variable is null, which crashes MicroRTS). It seems like python-microRTS ends the game before sending any actions.

This happens with both examples. Any tips on solving it?

douglasrizzo commented 4 years ago

The problem is that python-microRTS detects a gameover when the first JSON message received from MicroRTS starts with anything different that getAction. This happens in these lines.

But, as you can see from my previous message, when a game begins, a message is sent that begins with budget. This prompts python-microRTS to end the game. I'll try to find a fix for this tomorrow.

santiontanon commented 4 years ago

Hi Douglas, I do not maintain the python-microRTS side, but if there is anything I can do on the Java microRTS to address this issue, just let me know. If python-microRTS does not like those budget messages, maybe I can add some configuration options to the SocketAIs on the Java side to skip them on request. Just let me know.

douglasrizzo commented 4 years ago

Hello @santiontanon , I don't think there is any need to change the messages in microrts, as I was just able to find and fix the error I mention here in #3. Thank you for making yourself available.

santiontanon commented 4 years ago

ok! no problem! I hope your pull request is accepted, as it can be useful for many more people! :)