Practice/Meta/Go Scoreboard
CodingOptional
You are building a scoring system for a simplified territory control board game. The game is played on a 2D grid where each cell can be:
'')'w')'b')The scoring rules are:
Your task is to implement a function that calculates the final score and determines the winner.
calculateScore(board) that returns a string describing the outcome"White wins with X points", "Black wins with X points", or "Tie at X points each"findBestMove(board) that returns the coordinates (row, col) of the empty cell where white should place a piece to maximize their score gain'', 'w', or 'b'Example 1:
Input: [ ['w', 'w', ''], ['w', '', ''], ['', '', 'b'] ] Output: "White wins with 4 points" Explanation: White has 3 pieces (all connected with access to empty cells = 3 points). Black has 1 piece (with access to empty cells = 1 point). Wait, let me recalculate: White has 3 connected pieces, Black has 1 piece. Both have access to empty cells, so white scores 3, black scores 1. White wins with 3 points.
Example 2:
Input: [ ['b', 'b', 'b'], ['b', 'w', 'b'], ['b', 'b', 'b'] ] Output: "Black wins with 8 points" Explanation: The white piece in the center is completely surrounded by black with no adjacent empty cells, so it scores 0 points. Black has 8 pieces with access to the board edges (considered free), scoring 8 points.
Example 3:
Input: [ ['w', 'w', '', 'b', 'b'], ['w', '', '', '', 'b'], ['', '', 'w', 'w', ''], ['b', '', 'w', '', ''], ['b', 'b', '', '', ''] ] Output: "Black wins with 7 points" Explanation: All groups have access to empty cells. White has 6 pieces, black has 7 pieces. Black wins.