Skip to content

Commit

Permalink
make the lobby assign bots to remaining players when there is only on…
Browse files Browse the repository at this point in the history
…e human player
  • Loading branch information
nicolodavis committed Feb 11, 2020
1 parent ef8df65 commit 0eff1c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/lobby/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import React from 'react';
import Cookies from 'react-cookies';
import PropTypes from 'prop-types';
import { Client } from '../client/react';
import { MCTSBot } from '../ai/mcts-bot';
import { Local } from '../client/transport/local';
import { SocketIO } from '../client/transport/socketio';
import { LobbyConnection } from './connection';
import LobbyLoginForm from './login-form';
Expand Down Expand Up @@ -188,6 +190,15 @@ class Lobby extends React.Component {
}
}

if (gameOpts.numPlayers == 1) {
const maxPlayers = gameCode.game.maxPlayers;
let bots = {};
for (let i = 1; i < maxPlayers; i++) {
bots[i + ''] = MCTSBot;
}
multiplayer = Local({ bots });
}

const app = this.props.clientFactory({
game: gameCode.game,
board: gameCode.board,
Expand All @@ -198,7 +209,7 @@ class Lobby extends React.Component {
const game = {
app: app,
gameID: gameOpts.gameID,
playerID: gameOpts.numPlayers > 1 ? gameOpts.playerID : null,
playerID: gameOpts.numPlayers > 1 ? gameOpts.playerID : '0',
credentials: this.connection.playerCredentials,
};

Expand Down
3 changes: 2 additions & 1 deletion src/lobby/react.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,9 @@ describe('lobby', () => {
.simulate('click');
expect(lobby.instance().state.runningGame).toEqual({
app: NullComponent,
credentials: undefined,
gameID: 'gameID2',
playerID: null,
playerID: '0',
});
});

Expand Down

0 comments on commit 0eff1c6

Please sign in to comment.