Freebie: Local Python (2.7) Test Game Player
- Updated Sunday, February 7th 2016 @ 04:59:36
I put together a game player that runs Python bots locally, but I'm sure could be generalized for other purposes.
The gist: https://gist.github.com/kennytrytek/5c94ee113f1b6ba1e980
- Save the gist as test.py in a directory that houses your bots. Expected file structure is like this, where bot directory names are arbitrary, as long as they contain a runnable main.py:
/project_root --test.py --my_bot_1/main.py --random_bot/main.py
- To use, open a terminal to your project_root directory, and
python test.py
It will ask you which bots you want as player 1 and 2 (you can use the same bot for both), and then it should display the game field and each move as the bot makes it.
The program doesn't do a lot of error-checking. The only error-checking is whether a move is in an open location or not, so if your robot isn't respecting the macro board indicators, it won't help you. :)
Hope somebody finds this valuable. I have found it really helpful so far to be able to test my changes without having to wait for the online player to do it for me.
- Save the gist as test.py in a directory that houses your bots. Expected file structure is like this, where bot directory names are arbitrary, as long as they contain a runnable main.py:
- Created Sunday, February 7th 2016 @ 23:37:44
I'm not writing in Python, so I won't use it personally, but thanks a lot for making that! :)
- Created Monday, February 8th 2016 @ 15:53:15
Even if you're not using Python, I think it would be trivial to make it work for other languages. You would need to change the "get_bots" portion to find (or ask for a path to) your executable, and modify the Popen commands to execute that instead of 'main.py'. As long as your bot's output is correct and outputs via stdio, it should be functional with any executable.
- Created Wednesday, February 10th 2016 @ 13:30:52
This is amazing, I'm loving being able to test my latest version of code. Thank you HAL!
- Created Tuesday, April 12th 2016 @ 01:37:41
To be perfectly honest I had expected this sort of thing to already be in the getting started package. I have been coding around in Python myself, trying to accomplish something similar but I am unsure as to what you can and cannot change.
Very nice that you got this far HAL, great job!
- Updated Saturday, April 23rd 2016 @ 01:47:20
How would I debug my code while running this server? STDOUT is taken and writing to STDERR doesn't seem to be working either.
- Created Saturday, April 23rd 2016 @ 01:08:46
@alexlamson, I suppose you could write a debug log to a file and in a second terminal
tail -f debug.log
so as you write to the file you could see the output. That's not a great solution, but would be functional. - Created Saturday, April 23rd 2016 @ 01:48:45
Thank you for the helpful & speedy response HAL. I wasn't aware of the -f flag for tail, that seems quite useful.
Expl0itUpdated Monday, February 12th 2018 @ 23:08:2510000000146