Object-Oriented Programming · Databricks · Medium
Simulation with Board and Directional Scanning Checking the entire board after every move would be wasteful—a winning line must pass through the cell that was just played. So instead of scanning the whole grid, we only need to verify the four straight lines (horizontal, vertical, and the two diagonals) that go through (row, col). If any of these lines holds at least k consecutive pieces belonging to the player who just moved, that player wins immediately. The algorithm works…
Checking your access…