Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running .js or .ts javascript or typescript AI fail #50

Open
1000i100 opened this issue Dec 20, 2024 · 1 comment
Open

running .js or .ts javascript or typescript AI fail #50

1000i100 opened this issue Dec 20, 2024 · 1 comment

Comments

@1000i100
Copy link

i've tried similar command than the readme one :

$ java -jar ../cg-brutaltester-1.0.0.jar \
    -r "java --add-opens java.base/java.lang=ALL-UNNAMED -jar -Dleague.level=5 target/winter-2024-sprawl-1.0-SNAPSHOT.jar" \
    -p1 "node myAI.js" \
    -p2 "bun myAI.ts" \
    -s     \
    -t 4   \
    -l logs   \ 
    -n 1

but it fail ReferenceError: Can't find variable: readline in the logs.
We are talking about it here : #49
it look it's about stdin listening issue.
Is there a good way to use cg-brutaltester with javascript or typescript code ?

@1000i100
Copy link
Author

1000i100 commented Dec 21, 2024

I've found a way to make it work, inspired by : https://www.codingame.com/forum/t/javascript-how-to-make-readline-work-with-node/196950/
I use bun and TypeScript .ts files, but it also work with node and JavaScript .js files.
like describe there : https://forum.codingame.com/t/javascript-how-to-make-readline-work-with-node/196950/8
a polyfill.js and readline.js files are needed.
You can follow the bash script of the forum topic or download them from here :
typescriptStuff.zip
then you need launcher files to require the polyfill before launching your AI.
they just contain :

require("./polyfill")
require("./yourAI")

and of course, you need two AI to run the fight one against the other.

In short, you can run in your terminal :

(with git, java, maven, node or bun installed)

git clone https://github.com/aexg/WinterChallenge2024-Cellularena.git ./localChallenge
cd localChallenge
mvn package
wget https://github.com/dreignier/cg-brutaltester/releases/download/1.0.0/cg-brutaltester-1.0.0.jar
wget https://github.com/user-attachments/files/18216726/typescriptStuff.zip
unzip typescriptStuff.zip
java -jar ../cg-brutaltester-1.0.0.jar \
    -r "java --add-opens java.base/java.lang=ALL-UNNAMED -jar -Dleague.level=5 target/winter-2024-sprawl-1.0-SNAPSHOT.jar" \
    -p1 "bun launcher1.ts" \
    -p2 "bun launcher2.ts" \
    -s\
    -t 4\
    -n 1

and you should have 100% win for player 2
change waitAI.ts and/or emptyAI.ts with your AI in launcher{1|2}.ts and it should brutaltest the fight between your AI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant