Chess

From Computer Science Wiki
This a problem set for you to work through [1]

This is a problem set. Some of these are easy, others are far more difficult. The purpose of these problems sets are to HELP YOU THINK THROUGH problems. The solution is at the bottom of this page, but please don't look at it until you have tried (and failed) at least three or four times.

The Problem[edit]

This problem is designed to test your skill and knowledge of programming in python.


Some Code to Get You Started[edit]

# chess
board = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64]

def draw_board():
    row = 0
    for i in range(0,64):
        if "(" in board[i]:
            print("[" + str(board[i]) + "]"),
        else:
            print("[ " + str(i) + " ]")    
        row = row + 1
        if row == 8:
            print ("\n")
            row = 0 
    return

def initialize():
    for i in range(8,16):
        board[i] = "(p" + str(i-7) + ")"
    board[0] = "(r1)"    
    board[7] = "(r2)" 
    board[6] = "(n1)"
    board[1] = "(n2)"
    board[2] = "(b1)"
    board[5] = "(b2)"
    board[3] = "(Q)"
    board[4] = "(K)" 
    
    return



initialize() 
draw_board()

Take This Farther[edit]

  • If you manage to create a program to make valid chess moves, start builing a function that makes INTELLIGENT moves.

How you will be assessed[edit]

Every problem set is a formative assignment. Please click here to see how you will be graded

References[edit]

One Possible Solution[edit]

Click the expand link to see one possible solution, but NOT before you have tried and failed!

#
# this function returns a HTML opening and closing pair of tag
#

def make_tags(tag, word):

    print("<" + tag + ">" + word + "</" + tag + ">")

    return

# example input: 
# make_tags('i','Hello world')
 
# example output:
# <i>Hello world</i>