Skip to content

Fixed TicTacToe display bug - #1356

Merged
dmeoli merged 4 commits into
aimacode:masterfrom
levgrav:master
Nov 20, 2026
Merged

dmeoli merged 4 commits into
aimacode:masterfrom
levgrav:master

Conversation

@levgrav

@levgrav levgrav commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixed issue #1355 Display bug in games.py TicTacToe class and children

Fixed an issue where TicTacToe and child class games display with rows and columns swapped.

Changes:

  • aima/games.py lines 449,450, TicTacToe.display: Swapped x <-> y and self.h <-> self.v
  • aima/games.py line 472, ConnectFour.actions: Accounted for previous change to correctly check for cells below each move

Added:

  • tests/test_games.py: test_ttt_display_dimensions. Checks if TicTacToe or derivatives display with correct dimensions (e.g. a grid that is h x v). Fails without the previous changes, but succeeds with them.

Example of Issue

Previously a Connect Four board with default dimensions h=7, v=6 would display like this in an example game:

. . . . . . 
. . . . . . 
. . . . . . 
. . O . . . 
. . X O . . 
. O O X . . 
. X X X O . 

Moves: (7, 1), (5, 2), (3, 3), (4, 4), (6, 5), (7, 7) # displayed as (y, x)

Where it should look like:

. . . . . . .
. . . . . . .
. . O . . . .
. . X O . . .
. O O X . . .
. X X X O . .

Moves: (1, 6), (2, 4), (3, 2), (4, 3), (5, 4), (6, 6), (7, 7) # displayed as (x, y)

A TicTacToe or Gomoku game would also have the issue of reversed dimensions, except that they should be symmetric by default. They do display their actions as in the reversed format also: (y, x) instead of (x ,y)

@dmeoli

dmeoli commented Nov 20, 2026

Copy link
Copy Markdown
Member

thanks, the fix is right: with x as the column and y as the row, Connect Four now has 7 columns of 6 squares and the pieces fall to the bottom row
the test called display() without a state, so I passed game.initial and added a check that the first moves are the bottom row

@dmeoli
dmeoli merged commit 63afb16 into aimacode:master Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants