Why do all cells turn white when I double-click (so when I circle) a cell in my Hitori puzzle game in Python?

I’m working on a Hitori puzzle game in Python, and I’m facing an issue where if I double-click a cell, all the subsequent cells turn white (or clear). I’m using the boardgame library my professor gave us to create the game, and I’ve written custom code to handle the puzzle logic.

When I click on a cell, it triggers the play method, which updates the annotation for that cell, but, when i click twice (which serves as circling the number), instead of just updating that cell, all the other cells after it seem to reset to white or clear. The effect appears when clicking on any cell after the initial double-click.

The game works properly when there are just the annotations in place.

Can anyone help me understand why all the cells are turning white when I double-click on just one, and how I can fix this issue?

Here’s the relevant part of my code:

from boardgame import BoardGame
import csv
import g2d

class Hitori(BoardGame):
    CLEAR = 0
    BLACK = 1
    CIRCLE = 2

    def __init__(self):
        self._w, self._h = 5, 5
        self._numbers = []
        try:
            with open("5-easy.csv") as f:
                reader = csv.reader(f)
                for row in reader:
                    if len(row) != self._w:
                        raise ValueError(f"Each row must have exactly {self._w} numbers")
                    self._numbers.append(row)
        except FileNotFoundError:
            raise FileNotFoundError("File '5-easy.csv' not found")
        
        self._annots = [Hitori.CLEAR] * (self._w * self._h)

    def play(self, x, y, action):
        pos = x + y * self._w
        if action == "flag":
            self.fill(x, y)
        else:
            self._annots[pos] = (self._annots[pos] + 1) % 3

    def fill(self, x, y):
        pos = x + y * self._w
        if 0 <= x < self._w and 0 <= y < self._h and self._annots[pos] == Hitori.CLEAR:
            self._annots[pos] = Hitori.BLACK

    def read(self, x, y):
        try:
            cell_size = 40
            px, py = x * cell_size, y * cell_size
            txt = str(self._numbers[y][x])
            pos = x + y * self._w
            if self._annots[pos] == Hitori.BLACK:
                txt += "#"
                g2d.set_color((0, 0, 0))
                g2d.draw_rect((px, py), (40, 40))
            elif self._annots[pos] == Hitori.CIRCLE:
                txt += "!"
                g2d.set_color((0, 0, 0))
                g2d.set_stroke(2)
                g2d.draw_circle((px + 20, py + 20), 20)
            return txt
        except IndexError:
            return ""

    def finished(self):
        return all(annot != Hitori.CLEAR for annot in self._annots)

from boardgamegui import gui_play
gui_play(Hitori())

I tried double-clicking a cell in my Hitori puzzle game, which triggers the play method and updates the state of the clicked cell. I expected only that cell to change its state (toggle between CLEAR, BLACK, and CIRCLE), and I also expected the visual display of the game to update accordingly.

When I double-click on a cell, I expected only that cell’s state to toggle (from CLEAR to BLACK or CIRCLE), and the cell to be rendered accordingly.

What actually happened: When I double-click a cell, all the cells after the clicked cell turn white (clear), even though I only intended to modify the clicked cell.

I added a debug print statement inside the play method to check the state of self._annots after each action, but the issue still occurs.

I reviewed the fill method, which is used to mark cells as black, but I don’t see any reason why it would affect other cells.

New contributor

amaale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật