src/games/ToadsAndFrogs.js
/** The board of the next game state is calculated by applying the given move.
	*/
The board of the next game state is calculated by applying the given move.
The board of the next game state is calculated by applying the given move .
function next(moves, haps, update) {
		raiseIf(haps, 'Haps are not required (given ', haps, ')!');
		var activePlayer = this.activePlayer(), 
			move = moves[activePlayer], 
			chip = activePlayer.charAt(0),
			board = this.board,
			nextBoard;
		if (board.substr(move, 2) == 'T_') {
			nextBoard = board.substring(0, move) + '_T' + board.substring(move + 2);
		} else if (board.substr(move, 2) == '_F') {
			nextBoard = board.substring(0, move) + 'F_' + board.substring(move + 2);
		} else if (board.substr(move, 3) == 'TF_') {
			nextBoard = board.substring(0, move) + '_FT' + board.substring(move + 3);
		} else if (board.substr(move, 3) == '_TF') {
			nextBoard = board.substring(0, move) + 'FT_' + board.substring(move + 3);
		} else {
			throw new Error('Invalid move ', move, ' for board <', board, '>.');
		}
		if (update) {
			this.activatePlayers(this.opponent());
			this.board = nextBoard;
			return this;
		} else {
			return new this.constructor(this.opponent(), nextBoard);
		}
	}
function next ( moves , haps , update ) { raiseIf ( haps , 'Haps are not required (given ' , haps , ')!' ) ; var activePlayer = this . activePlayer ( ) , move = moves [ activePlayer ] , chip = activePlayer . charAt ( 0 ) , board = this . board , nextBoard ; if ( board . substr ( move , 2 ) == 'T_' ) { nextBoard = board . substring ( 0 , move ) + '_T' + board . substring ( move + 2 ) ; } else if ( board . substr ( move , 2 ) == '_F' ) { nextBoard = board . substring ( 0 , move ) + 'F_' + board . substring ( move + 2 ) ; } else if ( board . substr ( move , 3 ) == 'TF_' ) { nextBoard = board . substring ( 0 , move ) + '_FT' + board . substring ( move + 3 ) ; } else if ( board . substr ( move , 3 ) == '_TF' ) { nextBoard = board . substring ( 0 , move ) + 'FT_' + board . substring ( move + 3 ) ; } else { throw new Error ( 'Invalid move ' , move , ' for board <' , board , '>.' ) ; } if ( update ) { this . activatePlayers ( this . opponent ( ) ) ; this . board = nextBoard ; return this ; } else { return new this . constructor ( this . opponent ( ) , nextBoard ) ; } }
The board of the next game state is calculated by applying the given move.
The board of the next game state is calculated by applying the given move .