Tap here to switch tabs
Problem
Submissions

Problem: Check if Move is Legal

Check if Move is Legal asks whether placing a piece on an empty board cell creates a straight line of at least three cells with the move at one endpoint, matching endpoints, and opposite-colored pieces between them.

Statement

You are given an 8×88 \times 8 grid board representing a game board, where '.' denotes an empty cell, 'W' denotes a white piece, and 'B' denotes a black piece. You are also given integers rMove and cMove indicating the coordinates of an empty cell, and a character color representing the color of the piece to place at (rMove, cMove).

A move is considered legal if placing a piece of color color at cell (rMove, cMove) creates at least one good line where (rMove, cMove) is one of the endpoints.

A sequence of cells forms a good line if:

  • The line consists of at least 33 cells in a straight line extending in one of the 88 directions (horizontal, vertical, or diagonal).

  • Both endpoints of the line contain pieces of color color.

  • Every cell between the two endpoints contains a piece of the opposite color (neither empty '.' nor color).

Return true if the move is legal, or false otherwise.

Constraints:

  • board.length ==== board[r].length ==8== 8

  • 0≤0 \leq rMove, cMove <8< 8

  • board[rMove][cMove] ==== '.'

  • color is either 'B' or 'W'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Check if Move is Legal

Check if Move is Legal asks whether placing a piece on an empty board cell creates a straight line of at least three cells with the move at one endpoint, matching endpoints, and opposite-colored pieces between them.

Statement

You are given an 8×88 \times 8 grid board representing a game board, where '.' denotes an empty cell, 'W' denotes a white piece, and 'B' denotes a black piece. You are also given integers rMove and cMove indicating the coordinates of an empty cell, and a character color representing the color of the piece to place at (rMove, cMove).

A move is considered legal if placing a piece of color color at cell (rMove, cMove) creates at least one good line where (rMove, cMove) is one of the endpoints.

A sequence of cells forms a good line if:

  • The line consists of at least 33 cells in a straight line extending in one of the 88 directions (horizontal, vertical, or diagonal).

  • Both endpoints of the line contain pieces of color color.

  • Every cell between the two endpoints contains a piece of the opposite color (neither empty '.' nor color).

Return true if the move is legal, or false otherwise.

Constraints:

  • board.length ==== board[r].length ==8== 8

  • 0≤0 \leq rMove, cMove <8< 8

  • board[rMove][cMove] ==== '.'

  • color is either 'B' or 'W'