Python Chess-Style Gameboard Generator

import random,math,sys
import pygame
from pygame.locals import *
import os

pygame.init() #Initializing Pygame

screenwidth= 800
screenheight= 600
screen=pygame.display.set_mode((screenwidth,screenheight),0, 0)

def terminate():


def cookie(x,y):
    return random.randint(x,y)

tri = 9

while True:
    while tri==9:
        for event in pygame.event.get():
            if event.type == QUIT:
        x = 0
        y = 50
        w = 0
        while  x!=600:
               w = w+1
               if w%2==0:
               if x>=600 and y!=450:
                    if y<450:
                        x = 0
                        y = y+50
                    if y>=450:
    while tri==10:
        for event in pygame.event.get():
           if event.type == QUIT:

Below I’ve provided the images used and a screenshot of the code being utilized. You may notice the function “cookie” isn’t doing anything. I left in it there because you might find it useful. By using w = cookie(1,3) you can create a loop that will produce an image depending on what random number is generated (between one in three). You simply set up an image blit that varies depending on what the value of your “w” is following the execution of the “cookie” function. Lastly, I am using the term “chess-style” because it’s not a chess-board (it does not have the correct amount of spaces). However, you could easily change things up to generate a chess-board out of this code (I can’t do all the work). You might also use screenwidth to generate a “stop on condition x” that will be consistent regardless of your game dimensions (though this consistency would entail adding fewer or more squares). Anyway, I thought this code might be somewhat useful to the theoretical Pygamer. Enjoy.

Code Image
light blue square
purple square

This entry was posted in Pygame. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy this password:

* Type or paste password here: