--- /dev/null
+[flake8]
+ignore = E203, W503
+max-line-length = 88
--- /dev/null
+# Default ignored files\r
+/shelf/\r
+/workspace.xml\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<module type="PYTHON_MODULE" version="4">\r
+ <component name="NewModuleRootManager">\r
+ <content url="file://$MODULE_DIR$" />\r
+ <orderEntry type="inheritedJdk" />\r
+ <orderEntry type="sourceFolder" forTests="false" />\r
+ </component>\r
+</module>
\ No newline at end of file
--- /dev/null
+<component name="InspectionProjectProfileManager">
+ <settings>
+ <option name="USE_PROJECT_PROFILE" value="false" />
+ <version value="1.0" />
+ </settings>
+</component>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project version="4">\r
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />\r
+</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project version="4">\r
+ <component name="ProjectModuleManager">\r
+ <modules>\r
+ <module fileurl="file://$PROJECT_DIR$/.idea/Math-Puzzles.iml" filepath="$PROJECT_DIR$/.idea/Math-Puzzles.iml" />\r
+ </modules>\r
+ </component>\r
+</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project version="4">\r
+ <component name="VcsDirectoryMappings">\r
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />\r
+ </component>\r
+</project>
\ No newline at end of file
--- /dev/null
+MIT License
+
+Copyright (c) 2022 Georgios Atheridis
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
--- /dev/null
+class Board:\r
+ def __init__(self):\r
+ self.board = [[0 for _ in range(8)] for _ in range(8)]\r
+ self.board[0][0] = 1\r
+ self.board[0][1] = 1\r
+ self.board[1][0] = 1\r
+ self.win = False\r
+ self.print_board()\r
+\r
+ def _expand_board(self, units=1):\r
+ for i in range(units):\r
+ # add column\r
+ self.board.append([0 for _ in range(len(self.board[0]))])\r
+\r
+ # add row\r
+ for row in self.board:\r
+ row.append(0)\r
+\r
+ def play(self, posx, posy):\r
+ if self.board[posx][posy] == 1:\r
+ if self.board[posx + 1][posy] == 0 and self.board[posx][posy + 1] == 0:\r
+ self.board[posx + 1][posy] = 1\r
+ self.board[posx][posy + 1] = 1\r
+ self.board[posx][posy] = 0\r
+\r
+ if (\r
+ posx + 1 == len(self.board) - 1\r
+ or posy + 1 == len(self.board[posx]) - 1\r
+ ):\r
+ self._expand_board()\r
+ self.print_board()\r
+ self._check_win_con()\r
+\r
+ def _check_win_con(self):\r
+ if self.board[0][0] + self.board[0][1] + self.board[1][0] == 0:\r
+ self.win = True\r
+\r
+ def print_board(self):\r
+ for row in self.board:\r
+ print(row)\r
+\r
+ print()\r
--- /dev/null
+import pygame\r
+import sys\r
+from .board import Board\r
+\r
+\r
+class Game:\r
+ def __init__(\r
+ self,\r
+ screen_size=(800, 800),\r
+ square_size=100,\r
+ dark_square_colour=(0, 0, 0),\r
+ light_square_colour=(255, 255, 255),\r
+ ):\r
+\r
+ pygame.init()\r
+\r
+ self.screen_size = screen_size\r
+ self.square_size = square_size\r
+ self.dark_square_colour = dark_square_colour\r
+ self.light_square_colour = light_square_colour\r
+\r
+ self.screen = pygame.display.set_mode(self.screen_size)\r
+ pygame.display.set_caption("Pebbling a Chessboard")\r
+\r
+ self.board = Board()\r
+ self._draw_board()\r
+\r
+ def _draw_board(self):\r
+ # draw the squares\r
+ for row in range(8):\r
+ for col in range(4):\r
+ if row % 2 == 0:\r
+ pygame.draw.rect(\r
+ self.screen,\r
+ self.light_square_colour,\r
+ (\r
+ 2 * col * self.square_size,\r
+ row * self.square_size,\r
+ self.square_size,\r
+ self.square_size,\r
+ ),\r
+ )\r
+\r
+ pygame.draw.rect(\r
+ self.screen,\r
+ self.dark_square_colour,\r
+ (\r
+ (2 * col + 1) * self.square_size,\r
+ row * self.square_size,\r
+ self.square_size,\r
+ self.square_size,\r
+ ),\r
+ )\r
+ else:\r
+ pygame.draw.rect(\r
+ self.screen,\r
+ self.dark_square_colour,\r
+ (\r
+ 2 * col * self.square_size,\r
+ row * self.square_size,\r
+ self.square_size,\r
+ self.square_size,\r
+ ),\r
+ )\r
+\r
+ pygame.draw.rect(\r
+ self.screen,\r
+ self.light_square_colour,\r
+ (\r
+ (2 * col + 1) * self.square_size,\r
+ row * self.square_size,\r
+ self.square_size,\r
+ self.square_size,\r
+ ),\r
+ )\r
+\r
+ for row in range(8):\r
+ for col in range(8):\r
+ if self.board.board[row][col]:\r
+ posx = col * self.square_size + self.square_size / 2\r
+ posy = self.screen_size[0] - (\r
+ row * self.square_size + self.square_size / 2\r
+ )\r
+ pygame.draw.circle(self.screen, (255, 0, 0), (posx, posy), 40)\r
+\r
+ pygame.display.flip()\r
+\r
+ def handle_events(self):\r
+ for event in pygame.event.get():\r
+ if event.type == pygame.MOUSEBUTTONDOWN:\r
+ row = int((self.screen_size[0] - event.pos[1]) / self.square_size)\r
+ col = int(event.pos[0] / self.square_size)\r
+ if self.board.board[row][col]:\r
+ self.board.play(row, col)\r
+ elif event.type == pygame.QUIT:\r
+ pygame.quit()\r
+ sys.exit()\r
+ elif event.type == pygame.KEYDOWN:\r
+ if event.key == pygame.K_r:\r
+ self.board = Board()\r
+\r
+ def play(self):\r
+ while True:\r
+ self.handle_events()\r
+ self._draw_board()\r
--- /dev/null
+from .game import Game
+
+
+def main():
+ Game().play()
+
+
+if __name__ == "__main__":
+ main()
--- /dev/null
+black==22.6.0
+click==8.1.3
+flake8==4.0.1
+mccabe==0.6.1
+mypy-extensions==0.4.3
+pathspec==0.9.0
+platformdirs==2.5.2
+pycodestyle==2.8.0
+pyflakes==2.4.0
+pygame==2.1.2
+tomli==2.0.1
--- /dev/null
+from setuptools import setup, find_packages
+
+setup(
+ name="pebbling_a_chessboard",
+ version="0.0.1",
+ author="Georgios Atheridis",
+ author_email="atheridis@tutamail.com",
+ packages=find_packages(),
+ entry_points={
+ "console_scripts": [
+ "pebble-chessboard=pebbling_a_chessboard.main:main",
+ ],
+ },
+ install_requires=[
+ "pygame",
+ ],
+)