Spielerando

Check for four in a row in a drop-in column game without false wins

Scanning the whole board after every move is slow to write and easy to get wrong at the edges, and a board stored in one long list lets a line wrap from the end of one row to the start of the next. This entry checks only through the piece just dropped and handles a full board.

Why this works

Only the piece just dropped can have made a new line, so only the lines through its cell need a look. Counting outward in both directions on each line, and adding the piece itself, finds a win wherever the piece lands in the line.

When not to use it

If the board can change in other ways, such as pieces that vanish, rotate or shift the whole board, a win can appear without the last piece. Then check the whole board after each such change, not only around one cell.

In the full entry

  • What to build, step by step
  • Starting values and the reason for each
  • 4 common mistakes and the fix
  • A diagram of every state
  • 32 lines of example code with 4 checks that pass
  • How your AI shows you that it works

Say this to your AI

Use the Spielerando entry "Check for four in a row in a drop-in column game without false wins" (read_entry four-in-row-win-from-last-piece) in my game. Build it step by step, and show me how you checked that it works.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP