/** Drops a piece in the given column and updates the game state accordingly. */ function dropPiece(grid, status, game, column) { // Check if move is valid. if (game.state != "playing") { return; // or throw new Error("can't play in this game") } // Compute the lowest empty row in the selected column. let row = computeEmptyRow(game, column); let cell = row * 7 + column; // Update game state. game.board[cell] = game.next; // Check for winner / tie, will set game.state if game ended. checkWinner(game, cell); // Swap active player if (game.state == "playing") { togglePlayer(game); } // Update the HTML view. updateHtml(grid, game); // Update game status area to reflect active player / winner / tie updateStatus(status, game); }