diff --git a/src/components/farm/Board.jsx b/src/components/farm/Board.jsx index 143d9cd..ebbdd59 100644 --- a/src/components/farm/Board.jsx +++ b/src/components/farm/Board.jsx @@ -45,7 +45,7 @@ import { setSelectedCard, setMessagePanelSpace, setMPDims, movePlayer, setMovingSkip } from './actions.js' import { buy, roll, endTurn, loan, trade, submitTradeAccept, submitTradeDeny, submitTradeCancel, audit, - buyUncleBert, skip } from './interface.js' + buyUncleBert, skip, endAiTurn } from './interface.js' function netWorth(player) { return ((player.assets.hay + player.assets.grain) * 2000) + @@ -1447,9 +1447,11 @@ class Moving extends React.Component { render() { let buttons; - if (this.props.player.name !== this.props.game.currentPlayer) { + if ((this.props.player.name !== this.props.game.currentPlayer && + !this.props.currentPlayer.ai)) { buttons = (); - } else if (this.props.ui.playerSpaces[this.props.player.color] === this.props.ui.actionValue.to) { + } else if (this.props.ui.playerSpaces[(this.props.currentPlayer.ai && this.props.currentPlayer.color) || this.props.player.color] + === this.props.ui.actionValue.to) { buttons = (); } else { buttons = (); @@ -1479,7 +1481,8 @@ class Moving extends React.Component { class Action extends React.Component { render() { let view, buttons; - const currentPlayer = this.props.player.name === this.props.game.currentPlayer ? + const currentPlayer = (this.props.player.name === this.props.game.currentPlayer || + this.props.game.currentPlayer === '') ? this.props.player : this.props.game.otherPlayers .find(p => p.player.name === this.props.game.currentPlayer).player; switch (this.props.ui.action) { @@ -1587,6 +1590,7 @@ class Action extends React.Component { case 'move': view = ( this.props.showNextAction()} key={this.props.game.currentPlayer + '|' + this.props.ui.actionValue.from + '|' + this.props.ui.actionValue.to} + currentPlayer={currentPlayer} player={this.props.player} game={this.props.game} spaces={this.props.spaces} @@ -1601,6 +1605,7 @@ class Action extends React.Component { case 'resolve-move': view = ( this.props.showNextAction()} key={this.props.game.currentPlayer + '|' + this.props.ui.actionValue.from + '|' + this.props.ui.actionValue.to} + currentPlayer={currentPlayer} player={this.props.player} game={this.props.game} spaces={this.props.spaces} @@ -1615,6 +1620,7 @@ class Action extends React.Component { case 'goto': view = ( this.props.showNextAction()} timerId={this.props.timerId} + currentPlayer={currentPlayer} setTimerId={this.props.setTimerId} player={this.props.player} game={this.props.game} @@ -1635,11 +1641,13 @@ class Action extends React.Component { this.props.ui.actionValue.from - 49 : this.props.ui.actionValue.from); view = ( this.props.showNextAction() : false} autoSkip={this.props.ui.autoSkip} - skip={this.props.player.name === this.props.game.currentPlayer} + skip={(this.props.player.name === this.props.game.currentPlayer || + currentPlayer.ai)} showScreenDelay={2000} />); buttons = (); break; @@ -1650,6 +1658,12 @@ class Action extends React.Component { screen={this.props.screen} showScreen={this.props.showScreen} game={this.props.game} />); + } else if (currentPlayer.ai) { + view = ( + + ); } else { view = (Waiting for {this.props.game.currentPlayer}); } @@ -1663,7 +1677,7 @@ class Action extends React.Component {
- {this.props.otherPlayersTurn ? () : buttons} + {(this.props.otherPlayersTurn && !currentPlayer.ai ) ? () : buttons}
diff --git a/src/components/farm/interface.js b/src/components/farm/interface.js index fb004ba..ed6ce90 100644 --- a/src/components/farm/interface.js +++ b/src/components/farm/interface.js @@ -30,7 +30,7 @@ import { itemCard, fateCard } from 'game.js' export { initialize, buy, roll, endTurn, loan, trade, submitTradeAccept, submitTradeDeny, submitTradeCancel, audit, handleMessage, - nextAction, buyUncleBert, actionsFinished, skip } + nextAction, buyUncleBert, actionsFinished, skip, endAiTurn } let store; let movingTimer = 0; @@ -84,9 +84,14 @@ function handleMessage(evt) { store.dispatch(updateGame(data.game)); store.dispatch(setOldMessages(oldMessages)); store.dispatch(setCards(data.player.cards)); + const currentPlayer = (data.player.name === data.game.currentPlayer + || data.game.currentPlayer === '') ? + data.player : data.game.otherPlayers + .find(p => p.player.name === data.game.currentPlayer).player; if (data.event === 'action') { if (data.player.name !== data.game.currentPlayer && - data.action !== 'roll') { + data.action !== 'roll' && + !currentPlayer.ai) { store.dispatch(nextUIAction()); } store.dispatch(setNextAction(data.action, data.value)); @@ -136,6 +141,10 @@ function endTurn() { sendCommand({ type: 'turn-ended' }); } +function endAiTurn() { + sendCommand({ type: 'end-ai-turn' }); +} + function loan(amount) { sendCommand({ type: 'loan', amount: amount }); } @@ -192,10 +201,16 @@ function initialize(st, sc) { rollTimer = false, movingAction = { from: 99, to: 99 }, handledResolveMove = true; + const unsubscribe = store.subscribe( () => { const state = store.getState(); - if (state.farm.player.name === state.farm.game.currentPlayer + const currentPlayer = (state.farm.player.name === state.farm.game.currentPlayer + || state.farm.game.currentPlayer === '') ? + state.farm.player : state.farm.game.otherPlayers + .find(p => p.player.name === state.farm.game.currentPlayer).player; + if ((state.farm.player.name === state.farm.game.currentPlayer || + (currentPlayer.ai)) // TODO add test for first player, or something. only one player should be doing this && !state.farm.ui.actionChangeHandled) { store.dispatch(markActionChangeHandled()); nextAction(); diff --git a/src/components/farm/reducers.js b/src/components/farm/reducers.js index 2b44c7a..150ec51 100644 --- a/src/components/farm/reducers.js +++ b/src/components/farm/reducers.js @@ -95,7 +95,8 @@ const initialState = { space: 0, hayDoubled: false, cornDoubled: false, - trade: {} + trade: {}, + ai: false }, game: { calledAudit: false, currentPlayer: '',