8 Queens – WEEK 1 (Python)

Hi guys, today I’m going to write a post about my CT project. In this project I’m going to make 8 Queens, this is a game in which player is supposed to place 8 queens on the 8×8 board so that non of the queen is threat to other queen. In this post I will cover what platform I used to program this game.

I’m assuming that you have pre installed python in your systems. You can use any python compiler, but I will be using PyCharm. If you don’t have pyglet installed and synchronized with your favorite IDE/editor, here is a tutorial how to do it.

For this project we were supposed to divide our project work weekly and submit part of that week.

Week 1

So here is what I did in week 1:

  • Downloaded and installed PyCharm.
  • Installed and configured Pyglet.
  • Created 8×8 board on pyglet window.

I’m not going in the details about how I installed PyCharm. I will be writing up about my code, that I wrote to display 8×8 board on window.

import pyglet
from pyglet.window import Window, mouse, gl

#Display an image in the application window
bgimage = pyglet.image.load('resources/Board.gif')

#creating a window
mygame = Window(bgimage.width,bgimage.height,
   resizable = False,
   caption = "8 Queens",
   config = pyglet.gl.Config(double_buffer = True),
   vsync = False)

@mygame.event
def on_draw():
   mygame.clear()
   bgimage.blit(0,0)
	
def updated(dt):
   on_draw()

pyglet.clock.schedule_interval(updated, 1/60)

#Launch the application
pyglet.app.run()

This is the complete code to display 8×8 chess board on window. Before running this code you should make new folder, where your .py file is located, and name it ‘resources’. We will be using resources folder to save our media files. Now download this image below and save it as Board.gif in resources folder that we just created.board

This is what I did in first week. Next week I’m planning to calculate the height and width of each tile, and store them somewhere.

Advertisements

2 Comments Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s