Skip to content

Commit

Permalink
Fix ending_bot crash
Browse files Browse the repository at this point in the history
Closes #410
  • Loading branch information
raylu committed Sep 24, 2023
1 parent 7b063ee commit 0a10527
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ __pycache__
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml
.nyc_output
/coverage

# Translations
*.mo
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ npm install -g gtp2ogs

### Building from source

To build from source you will need to have `node.js` installed on your system.
You will also need to have the `yarn` and `gulp` npm packages installed. Once
you have the prerequisites you can run `yarn` to install the package dependencies,
and

To build from source you will need to have node.js installed on your system.
You will also need to have `yarn` installed. Then, run
```
gulp
yarn install
yarn exec -- gulp
```

to run the build process. The resulting compiled javascript file will be located
Expand All @@ -51,6 +49,12 @@ in `dist/gtp2ogs.js` which you can then run with
node dist/gtp2ogs.js
```

If you do not want to install node.js and yarn locally, another option is
```
docker run --rm -it -v "$PWD":/usr/src -w /usr/src node:slim yarn install
docker run --rm -it -v "$PWD":/usr/src -w /usr/src node:slim yarn exec -- gulp
```

## Running your bot

Once you have your API Key and `gtp2ogs` installed, you can connect your bot to OGS
Expand Down
17 changes: 11 additions & 6 deletions src/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,17 @@ export class Game extends EventEmitter<Events> {
decodeMoves(move.move, this.state.width, this.state.height)[0],
this.state.width,
this.state.height,
this.my_color === "black" ? "white" : "black",
"black", // we are white so we are recording black's moves
),
);
}
if (this.ending_bot) {
ignore_promise(
this.ending_bot?.sendMove(
this.ending_bot.sendMove(
decodeMoves(move.move, this.state.width, this.state.height)[0],
this.state.width,
this.state.height,
this.my_color === "black" ? "white" : "black",
"black",
),
);
}
Expand All @@ -301,6 +303,7 @@ export class Game extends EventEmitter<Events> {
}
}
} else {
const opponent_color = this.my_color === "black" ? "white" : "black";
if (move.move_number % 2 === this.opponent_evenodd) {
// We just got a move from the opponent, so we can move immediately.
//
Expand All @@ -310,15 +313,17 @@ export class Game extends EventEmitter<Events> {
decodeMoves(move.move, this.state.width, this.state.height)[0],
this.state.width,
this.state.height,
this.my_color === "black" ? "white" : "black",
opponent_color,
),
);
}
if (this.ending_bot) {
ignore_promise(
this.ending_bot?.sendMove(
this.ending_bot.sendMove(
decodeMoves(move.move, this.state.width, this.state.height)[0],
this.state.width,
this.state.height,
this.my_color === "black" ? "white" : "black",
opponent_color,
),
);
}
Expand Down

0 comments on commit 0a10527

Please sign in to comment.