For some reason my algorithm isn’t able to write files.
I put these three lines into my on_game_start method:
file = open(“testfile.txt”,“w”)
file.write(“test”)
file.close()
Then I ran run_match.ps1
everything worked fine except for the fact that the file wasn’t written.
I also tried using os:
import os.path
completeName = os.path.join(‘C:/(Path)/’,‘log.txt’)
file = open(completeName, “w”)
file.write(“test”)
file.close()
But it didn’t work either.
What am I missing?
Make sure you are looking in the right folder. It will create the file in whatever directory PowerShell or terminal is in, NOT the folder containing the python script. Check to see if the file is in your main folder.
The file is not in the main folder.
It seems like even though the algorithm runs normally when uploaded and no errors are thrown in the powershell it does not run locally: no gamelib.debug_write commands are written into the powershell and when I create an algorithm that doesn’t place anything it still sometimes wins against the starter algorithm.
Another strange thing I noticed is that an empty error file temporarily appears in my algo’s folder with a name like “errorFile112-10-2018-10-51-45-1539334305037–1986450257.txt”
When updating my starter kit to the current github version I get the error described in When running `scripts\run_match.ps1` I receive many counts of error
I believe your two errors may be independent of one another. The only way I can replicate your file problem is if I put it in the on_game_start
inside the algocore.py file. This function is overwritten by AlgoStrategy.py and thus will not run if you put it in the wrong one.
Regarding your other issue (which may be related depending), can you check what the error file says? It may give insight as to where the problem occurred.
Also, check what version of python you have installed (run py -V
in PowerShell).
Lastly, were you able to run the game before trying to write to a file? Try downloading a fresh version (in some new folder) and running it completely vanilla.
There is a technical possibility that your file output is being routed to the stdout (what the program uses to communicate, hence the JSON error) but I have no idea how that would happen without you explicitly telling it to do that. So until a lot more stuff is checked I consider this extremely unlikely.
There can’t be anything wrong with the algorithm because if I upload it and play against it it does what it is supposed to do.
The error file is empty and deletes itself as soon as the game has ended.
py -V outputs Python 3.6.5
I am able to run the game and have always been able to run it as long as I use the old version.
When downloading a fresh Version I get the errors described in When running `scripts\run_match.ps1` I receive many counts of error so I can’t download a fresh version but when only replacing the old algorithm with a fresh one nothing changes.
This is the output when I let a fresh starter-algo battle itself:
p1:
C:\Users\myname\Terminal\C1GamesStarterKit-master\algos\starter-algo\run.ps1
p2:
C:\Users\myname\Terminal\C1GamesStarterKit-master\algos\starter-algo\run.ps1
Starting Engine
Starting single worker game.
P1 Name: starter-algo
P2 Name: starter-algo
Winner (p1 perspective, 1 = p1 2 = p2): 1
Waiting to exit finished game.
Done waiting now exiting finished game.
Hard Exiting Now
Closing stream
kill -9060
kill 5716
Closing stream
kill -244
kill 4528
Exited for loop
End of main
Closing stream
kill 5716
Closing stream
kill 4528
What about the error file that was generated?
There was no error file generated except for the empty one
I think this Thread has become obsolete because Local run not working on Windows sums all my problems up