TensorTonic
Study Plans
Study Plan
Apply a Go Action with Captures and Repetition
Reinforcement LearningData Processing
Hard

Apply one already-legal Go action to a nonterminal state. The board uses 0 for empty, 1 for Black, and -1 for White. For a board with side length n, intersection actions use row-major indices from 0 to n squared minus one; action n squared means pass.

A stone placement captures each adjacent opposing group with no remaining liberties. Groups connect horizontally or vertically, and a liberty is an adjacent empty intersection. This task receives a legal action, so occupancy, suicide, and repetition checks are not required.

Return a six-item tuple containing a NumPy array for the next board, next player, captured-stone count, consecutive-pass count, move count, and Boolean terminal flag. The player and counters are integers; the board keeps its original shape and uses -1, 0, and 1 for its entries.

Loading visualization...

Examples

Input: board = [[0,0],[0,0]], player = 1, action = 4, consecutive_passes = 0, move_count = 0

Output: ([[0,0],[0,0]], -1, 0, 1, 1, False)

Explanation: Pass leaves the board unchanged, switches the player, and increments both counters.

Input: board = [[1,-1,0],[0,1,0],[0,0,0]], player = 1, action = 2, consecutive_passes = 0, move_count = 4

Output: ([[1,0,1],[0,1,0],[0,0,0]], -1, 1, 0, 5, False)

Input: board = [[1,0],[0,-1]], player = -1, action = 4, consecutive_passes = 1, move_count = 3

Output: ([[1,0],[0,-1]], 1, 0, 2, 4, True)

Hint 1

divmod(action, board_size) maps a non-pass action to its coordinates.

Hint 2

A set of captured coordinates avoids counting the same group twice.

Hint 3

Use the updated counters to determine the terminal flag.

Requirements

  • Use NumPy and preserve the supplied board.
  • Switch the player and increment move count after every action, including pass.
  • A placement resets consecutive passes to zero. A pass leaves the board values unchanged, captures no stones, and increments consecutive passes.
  • The result is terminal after at least two consecutive passes or at least twice the board area in played actions.

Constraints

  • The board is a nonempty square nested Python list containing -1, 0, or 1.
  • Player is 1 or -1.
  • Action is a valid integer intersection or pass index.
  • The supplied action is legal and the state is nonterminal.
  • Consecutive passes and move count are nonnegative integers.
Try Similar Problems
Build the Legal Go Action MaskHardScore a Terminal Position with Tromp-Taylor RulesMediumFind a Go Group and Its LibertiesEasyApply a Dihedral Go SymmetryMediumEncode AlphaGo Zero Board HistoryMediumSample a Recent Self-Play Replay BatchEasyCanonicalize Pairwise Preference DataMediumApply One Policy-Value Head Training StepHardExperience Replay BufferEasyApply Custom TransformsHardGRPO Group-Relative AdvantageHardBoolean MaskingHard

Accepts: array

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.

Apply a Go Action with Captures and Repetition

Reinforcement LearningData Processing
Hard

Apply one already-legal Go action to a nonterminal state. The board uses 0 for empty, 1 for Black, and -1 for White. For a board with side length n, intersection actions use row-major indices from 0 to n squared minus one; action n squared means pass.

A stone placement captures each adjacent opposing group with no remaining liberties. Groups connect horizontally or vertically, and a liberty is an adjacent empty intersection. This task receives a legal action, so occupancy, suicide, and repetition checks are not required.

Return a six-item tuple containing a NumPy array for the next board, next player, captured-stone count, consecutive-pass count, move count, and Boolean terminal flag. The player and counters are integers; the board keeps its original shape and uses -1, 0, and 1 for its entries.

Loading visualization...

Examples

Input: board = [[0,0],[0,0]], player = 1, action = 4, consecutive_passes = 0, move_count = 0

Output: ([[0,0],[0,0]], -1, 0, 1, 1, False)

Explanation: Pass leaves the board unchanged, switches the player, and increments both counters.

Input: board = [[1,-1,0],[0,1,0],[0,0,0]], player = 1, action = 2, consecutive_passes = 0, move_count = 4

Output: ([[1,0,1],[0,1,0],[0,0,0]], -1, 1, 0, 5, False)

Input: board = [[1,0],[0,-1]], player = -1, action = 4, consecutive_passes = 1, move_count = 3

Output: ([[1,0],[0,-1]], 1, 0, 2, 4, True)

Hint 1

divmod(action, board_size) maps a non-pass action to its coordinates.

Hint 2

A set of captured coordinates avoids counting the same group twice.

Hint 3

Use the updated counters to determine the terminal flag.

Requirements

  • Use NumPy and preserve the supplied board.
  • Switch the player and increment move count after every action, including pass.
  • A placement resets consecutive passes to zero. A pass leaves the board values unchanged, captures no stones, and increments consecutive passes.
  • The result is terminal after at least two consecutive passes or at least twice the board area in played actions.

Constraints

  • The board is a nonempty square nested Python list containing -1, 0, or 1.
  • Player is 1 or -1.
  • Action is a valid integer intersection or pass index.
  • The supplied action is legal and the state is nonterminal.
  • Consecutive passes and move count are nonnegative integers.
Try Similar Problems
Build the Legal Go Action MaskHardScore a Terminal Position with Tromp-Taylor RulesMediumFind a Go Group and Its LibertiesEasyApply a Dihedral Go SymmetryMediumEncode AlphaGo Zero Board HistoryMediumSample a Recent Self-Play Replay BatchEasyCanonicalize Pairwise Preference DataMediumApply One Policy-Value Head Training StepHardExperience Replay BufferEasyApply Custom TransformsHardGRPO Group-Relative AdvantageHardBoolean MaskingHard

Accepts: array

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.