TensorTonic
Study Plans
Study Plan
Encode AlphaGo Zero Board History
Reinforcement LearningData ProcessingFeature Engineering
Medium

Encode the current board and up to seven earlier boards from the current player's perspective. History is a newest-first list of PyTorch tensors, with 0 for empty, 1 for Black, and -1 for White.

S=[X0,Y0,X1,Y1,…,X7,Y7,C]S=[X_0,Y_0,X_1,Y_1,\ldots,X_7,Y_7,C]S=[X0​,Y0​,X1​,Y1​,…,X7​,Y7​,C]

Here, X and Y at history step t mark the current player's and opponent's stones, respectively. C contains ones when Black is to play or zeros when White is to play. Each stone plane contains ones at matching intersections and zeros elsewhere; missing history steps contribute two zero planes. The same current-player perspective applies to every history step.

Return S as a PyTorch float32 tensor of shape (17, board size, board size) on the same device as the input tensors.

Loading visualization...

Examples

Input: history = [[[1,0],[-1,1]]], to_play = 1

Output: [[[1,0],[0,1]],[[0,0],[1,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[1,1],[1,1]]]

Explanation: The first two planes encode Black and White, the missing history planes are zero, and the final plane marks Black to play.

Input: history = [[[1,-1],[0,-1]]], to_play = -1

Output: 32-bit floating-point tensor with shape (17,2,2)

Input: history = [[[1,-1,0],[0,1,0],[0,0,-1]],[[1,-1,0],[0,0,0],[0,0,-1]]], to_play = 1

Output: 32-bit floating-point tensor with shape (17,3,3)

Hint 1

Tensor equality produces a Boolean plane; .float() converts it to float32.

Hint 2

torch.zeros can create missing planes on the input device.

Hint 3

torch.stack combines the planes along a new leading dimension.

Requirements

  • Use PyTorch and return float32 values.
  • Preserve the input device and do not mutate any history tensor.

Constraints

  • History contains one to eight nonempty square tensors ordered newest first.
  • Every board uses the same shape and device.
  • Board values are -1, 0, or 1.
  • The current player is represented by 1 or -1.
Try Similar Problems
Apply a Dihedral Go SymmetryMediumScore a Terminal Position with Tromp-Taylor RulesMediumCompute the Policy and Value HeadsMediumApply an AlphaGo Residual BlockMediumFind a Go Group and Its LibertiesEasyApply a Go Action with Captures and RepetitionHardBuild the Legal Go Action MaskHardSample a Recent Self-Play Replay BatchEasyNormalize ColumnsMediumMissing Value ImputationEasyAngle FeaturesEasyExperience Replay BufferEasy

Accepts: array

Accepts: number

You must run your code first.

Encode AlphaGo Zero Board History

Reinforcement LearningData ProcessingFeature Engineering
Medium

Encode the current board and up to seven earlier boards from the current player's perspective. History is a newest-first list of PyTorch tensors, with 0 for empty, 1 for Black, and -1 for White.

S=[X0,Y0,X1,Y1,…,X7,Y7,C]S=[X_0,Y_0,X_1,Y_1,\ldots,X_7,Y_7,C]S=[X0​,Y0​,X1​,Y1​,…,X7​,Y7​,C]

Here, X and Y at history step t mark the current player's and opponent's stones, respectively. C contains ones when Black is to play or zeros when White is to play. Each stone plane contains ones at matching intersections and zeros elsewhere; missing history steps contribute two zero planes. The same current-player perspective applies to every history step.

Return S as a PyTorch float32 tensor of shape (17, board size, board size) on the same device as the input tensors.

Loading visualization...

Examples

Input: history = [[[1,0],[-1,1]]], to_play = 1

Output: [[[1,0],[0,1]],[[0,0],[1,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[0,0],[0,0]],[[1,1],[1,1]]]

Explanation: The first two planes encode Black and White, the missing history planes are zero, and the final plane marks Black to play.

Input: history = [[[1,-1],[0,-1]]], to_play = -1

Output: 32-bit floating-point tensor with shape (17,2,2)

Input: history = [[[1,-1,0],[0,1,0],[0,0,-1]],[[1,-1,0],[0,0,0],[0,0,-1]]], to_play = 1

Output: 32-bit floating-point tensor with shape (17,3,3)

Hint 1

Tensor equality produces a Boolean plane; .float() converts it to float32.

Hint 2

torch.zeros can create missing planes on the input device.

Hint 3

torch.stack combines the planes along a new leading dimension.

Requirements

  • Use PyTorch and return float32 values.
  • Preserve the input device and do not mutate any history tensor.

Constraints

  • History contains one to eight nonempty square tensors ordered newest first.
  • Every board uses the same shape and device.
  • Board values are -1, 0, or 1.
  • The current player is represented by 1 or -1.
Try Similar Problems
Apply a Dihedral Go SymmetryMediumScore a Terminal Position with Tromp-Taylor RulesMediumCompute the Policy and Value HeadsMediumApply an AlphaGo Residual BlockMediumFind a Go Group and Its LibertiesEasyApply a Go Action with Captures and RepetitionHardBuild the Legal Go Action MaskHardSample a Recent Self-Play Replay BatchEasyNormalize ColumnsMediumMissing Value ImputationEasyAngle FeaturesEasyExperience Replay BufferEasy

Accepts: array

Accepts: number

You must run your code first.