I2P-Bernard-FULLCODE

This is the full code for my Final Project:

from random import randint

board = []

COOL_COLOR      = 0
NOT_COOL_COLOR  = 1
BOARD_WIDTH     = 10
TOP_MARGIN      = 5
class bcolors:
    BLUE  = '\033[94m'
RED   = '\033[31m'
GREEN = '\033[92m'
BOLD  = '\033[1m'
ENDC = '\033[0m'
UNDERLINE = '\033[4m'
def col_print(color, message):
    if color == COOL_COLOR:
        print bcolors.BLUE + message + bcolors.ENDC,
    elif color == NOT_COOL_COLOR:
        print bcolors.RED + message + bcolors.ENDC,
    else:
        print message

for x in range(10):
    board.append(["O"] * 10)

def print_board(board):
    for i in range(TOP_MARGIN):
        print " "
print "                    ==================="
print " "
for row in range(BOARD_WIDTH):
        print "                   ",
        for col in range(BOARD_WIDTH):
            if board[row][col] == "h":
                col_print(NOT_COOL_COLOR, "H")
            elif board[row][col] == "L":
                col_print(NOT_COOL_COLOR, "G")
            elif board[row][col] == "F":
                col_print(NOT_COOL_COLOR, "g")
            elif board[row][col] == "Y":
                col_print(NOT_COOL_COLOR, "C")
            elif board[row][col] == "d":
                col_print(NOT_COOL_COLOR, "A")
            elif board[row][col] == "X":
                col_print(NOT_COOL_COLOR, "S")
            elif board[row][col] == "O":
                print board[row][col],
            else:
                col_print(COOL_COLOR, board[row][col])
        print " "
print " "
print "                    ==================="
"""
def print_board(board):
    for x in board:
        print " ".join(x)
"""
def set_home_position(board):
    board[0][5] = "h"
board[9][5] = "H"
#main program start
option = raw_input ("Hello. Welcome to the Army Game. Do you want to play? Yes(Y) or No(N)? :")

if option == "Yes" or option == "yes" or option == 'Y' or option == 'y':
    print "Here are the rules:"
print "1. You are playing against the computer and both of you will have 5 players"
print "2. The 5 players are (General, Archer, Grenade, Cannon, Soldier) and they are ranked from top to bottom in that specific order"
print "3. You can only kill players that are a lower rank than you, and you cannot kill players that are a higher rank than you"
print "4. If you kill a player that is your own rank, than both of the players die"
print "5. Friendly fire is not tolerated"
print "6. You may only move 1 player every turn"
print "7. You may only move either 1 step vertically or 1 step horizontally, you may not move diagonally"
print "8. First one to reach the opponent's home(H) wins"
print "9. You are color BLUE, the computer is color RED"
raw_input("Hit any key to continue ...")

    print ""
print "To start, you must choose specify locations of your players"
else:
    print "Okay, see you next time!"
exit()


set_home_position(board)
print_board(board)

#general
guess_row_general = 8
x = False
while (x == False):
    guess_col_general = int(raw_input ("Insert general col:"))
    if board[guess_row_general][guess_col_general] != "O":
        print "Sorry, this spot is already occupied"
x = False
else:
        x = True
board[guess_row_general][guess_col_general] = "G"
#archer
guess_row_archer = 8
x = False
while (x == False):
    guess_col_archer = int(raw_input ("Insert archer col:"))
    if board[guess_row_archer][guess_col_archer] != "O":
        print "Sorry, this spot is already occupied"
x = False
else:
        x = True
board[guess_row_archer][guess_col_archer] = "A"
#grenade
guess_row_grenade = 8
x = False
while (x == False):
    guess_col_grenade = int(raw_input ("Insert grenade col:"))
    if board[guess_row_grenade][guess_col_grenade] != "O":
        print "Sorry, this spot is already occupied"
x = False
else:
        x = True
board[guess_row_grenade][guess_col_grenade] = "g"
#cannon
guess_row_cannon = 8
x = False
while (x == False):
    guess_col_cannon = int(raw_input ("Insert cannon col:"))
    if board[guess_row_cannon][guess_col_cannon] != "O":
        print "Sorry, this spot is already occupied"
x = False
else:
        x = True
board[guess_row_cannon][guess_col_cannon] = "C"
#soldier
guess_row_soldier = 8
x = False
while (x == False):
    guess_col_soldier = int(raw_input ("Insert soldier col:"))
    if board[guess_row_soldier][guess_col_soldier] != "O":
        print "Sorry, this spot is already occupied"
x = False
else:
        x = True
board[guess_row_soldier][guess_col_soldier] = "S"
#computer general
comp_row_general = 1
x = False
while (x == False):
    comp_col_general = randint(0, 9)
    if board[comp_row_general][comp_col_general] != "O":
        x = False
else:
        x = True
board[comp_row_general][comp_col_general] = "L"
#computer archer
comp_row_archer = 1
x = False
while (x == False):
    comp_col_archer = randint(0, 9)
    if board[comp_row_archer][comp_col_archer] != "O":
        x = False
else:
        x = True
board[comp_row_archer][comp_col_archer] = "d"
#computer grenade
comp_row_grenade = 1
x = False
while (x == False):
    comp_col_grenade = randint(0, 9)
    if board[comp_row_grenade][comp_col_grenade] != "O":
        x = False
else:
        x = True
board[comp_row_grenade][comp_col_grenade] = "F"
#computer cannon
comp_row_cannon = 1
x = False
while (x == False):
    comp_col_cannon = randint(0, 9)
    if board[comp_row_cannon][comp_col_cannon] != "O":
        x = False
else:
        x = True
board[comp_row_cannon][comp_col_cannon] = "Y"
#computer soldier
comp_row_soldier = 1
x = False
while (x == False):
    comp_col_soldier = randint(0, 9)
    if board[comp_row_soldier][comp_col_soldier] != "O":
        x = False
else:
        x = True
board[comp_row_soldier][comp_col_soldier] = "X"
print "\n\nGAME START"
set_home_position(board)
print_board (board)



y = True
num_turn = 0
while (y == True):
    num_turn += 1
print "Turn: ", num_turn
    the_choice = raw_input("Which person would you like to move? General, Archer, Grenade, Cannon, or Soldier? :")
    if the_choice == "General" or the_choice == "general":
        x = False
while (x == False):
            user_general_row = int(raw_input ("Insert the new general row:"))
            user_general_col = int(raw_input ("Insert thew new general col:"))
            if board[user_general_row][user_general_col] == "G" or board[user_general_row][user_general_col] == "A" or board[user_general_row][user_general_col] == "g" or board[user_general_row][user_general_col] == "C" or board[user_general_row][user_general_col] == "S":
                print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_general_row) - int (guess_row_general)) == 1 and abs(int(user_general_col) - int(guess_col_general)) == 1:
                print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_general_row) - int (guess_row_general)) > 1 or abs(int(user_general_col) - int(guess_col_general)) > 1:
                print "invalid, sorry. Please re-enter position"
x = False
elif board[user_general_row][user_general_col] == "L":
                board[user_general_row][user_general_col] = "O"
board[guess_row_general][guess_col_general] = "O"
board[comp_row_general][comp_col_general] = "O"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_general_row][user_general_col] == "d" or board[user_general_row][user_general_col] == "F" or board[user_general_row][user_general_col] == "Y" or board[user_general_row][user_general_col] == "X" or board[user_general_row][user_general_col] == "O":
                board[user_general_row][user_general_col] = "G"
board[guess_row_general][guess_col_general] = "O"
guess_row_general = user_general_row
                guess_col_general = user_general_col
                set_home_position(board)
                print_board (board)
                x = True
elif board[user_general_row][user_general_col] == "h":
                print "Congratulations! You won the game!!!"
break
        if x == True:
            y = True
else:
            break
    elif the_choice == "Archer" or the_choice == "archer":
        x = False
while (x == False):
            user_archer_row = int(raw_input ("Insert the new archer row:"))
            user_archer_col = int(raw_input ("Insert thew new archer col:"))
            if board[user_archer_row][user_archer_col] == "G" or board[user_archer_row][user_archer_col] == "A" or board[user_archer_row][user_archer_col] == "g" or board[user_archer_row][user_archer_col] == "C" or board[user_archer_row][user_archer_col] == "S":
                print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_archer_row) - int (guess_row_archer)) == 1 and abs(int(user_archer_col) - int(guess_col_archer)) == 1:
                print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_archer_row) - int (guess_row_archer)) > 1 or abs(int(user_archer_col) - int(guess_col_archer)) > 1:
                print "invalid, sorry. Please re-enter position"
x = False
elif board[user_archer_row][user_archer_col] == "d":
                board[user_archer_row][user_archer_col] = "O"
board[guess_row_archer][guess_col_archer] = "O"
board[comp_row_archer][comp_col_archer] = "O"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_archer_row][user_archer_col] == "L":
                board[user_archer_row][user_archer_col] = "O"
board[guess_row_archer][guess_col_archer] = "O"
board[comp_row_general][comp_col_general] = "L"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_archer_row][user_archer_col] == "F" or board[user_archer_row][user_archer_col] == "Y" or board[user_archer_row][user_archer_col] == "X" or board[user_archer_row][user_archer_col] == "O":
                board[user_archer_row][user_archer_col] = "A"
board[guess_row_archer][guess_col_archer] = "O"
guess_row_archer = user_archer_row
                guess_col_archer = user_archer_col
                set_home_position(board)
                print_board (board)
                x = True
elif board[user_archer_row][user_archer_col] == "h":
                print "Congratulations! You won the game!!!"
break
        if x == True:
            y = True
else:
            break
    elif the_choice == "Grenade" or the_choice == "grenade":
        x = False
while (x == False):
            user_grenade_row = int(raw_input ("Insert the new grenade row:"))
            user_grenade_col = int(raw_input ("Insert thew new grenade col:"))
            if board[user_grenade_row][user_grenade_col] == "G" or board[user_grenade_row][user_grenade_col] == "A" or board[user_grenade_row][user_grenade_col] == "g" or board[user_grenade_row][user_grenade_col] == "C" or board[user_grenade_row][user_grenade_col] == "S":
                print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_grenade_row) - int (guess_row_grenade)) == 1 and abs(int(user_grenade_col) - int(guess_col_grenade)) == 1:
                print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_grenade_row) - int (guess_row_grenade)) > 1 or abs(int(user_grenade_col) - int(guess_col_grenade)) > 1:
                print "invalid, sorry. Please re-enter position"
x = False
elif board[user_grenade_row][user_grenade_col] == "F":
                board[user_grenade_row][user_grenade_col] = "O"
board[guess_row_grenade][guess_col_grenade] = "O"
board[comp_row_grenade][comp_col_grenade] = "O"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_grenade_row][user_grenade_col] == "L":
                board[user_grenade_row][user_grenade_col] = "O"
board[guess_row_grenade][guess_col_grenade] = "O"
board[comp_row_general][comp_col_general] = "L"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_grenade_row][user_grenade_col] == "d":
                board[user_grenade_row][user_grenade_col] = "O"
board[guess_row_grenade][guess_col_grenade] = "O"
board[comp_row_archer][comp_col_archer] = "d"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_grenade_row][user_grenade_col] == "Y" or board[user_grenade_row][user_grenade_col] == "X" or board[user_grenade_row][user_grenade_col] == "O":
                board[user_grenade_row][user_grenade_col] = "g"
board[guess_row_grenade][guess_col_grenade] = "O"
guess_row_grenade = user_grenade_row
                guess_col_grenade = user_grenade_col
                set_home_position(board)
                print_board (board)
                x = True
elif board[user_grenade_row][user_grenade_col] == "h":
                print "Congratulations! You won the game!!!"
break
        if x == True:
            y = True
else:
            break
    elif the_choice == "Cannon" or the_choice == "cannon":
        x = False
while (x == False):
            user_cannon_row = int(raw_input ("Insert the new cannon row:"))
            user_cannon_col = int(raw_input ("Insert thew new cannon col:"))
            if board[user_cannon_row][user_cannon_col] == "G" or board[user_cannon_row][user_cannon_col] == "A" or board[user_cannon_row][user_cannon_col] == "g" or board[user_cannon_row][user_cannon_col] == "C" or board[user_cannon_row][user_cannon_col] == "S":
                print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_cannon_row) - int (guess_row_cannon)) == 1 and abs(int(user_cannon_col) - int(guess_col_cannon)) == 1:
                print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_cannon_row) - int (guess_row_cannon)) > 1 or abs(int(user_cannon_col) - int(guess_col_cannon)) > 1:
                print "invalid, sorry. Please re-enter position"
x = False
elif board[user_cannon_row][user_cannon_col] == "Y":
                board[user_cannon_row][user_cannon_col] = "O"
board[guess_row_cannon][guess_col_cannon] = "O"
board[comp_row_cannon][comp_col_cannon] = "O"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_cannon_row][user_cannon_col] == "L":
                board[user_cannon_row][user_cannon_col] = "O"
board[guess_row_cannon][guess_col_cannon] = "O"
board[comp_row_general][comp_col_general] = "L"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_cannon_row][user_cannon_col] == "d":
                board[user_cannon_row][user_cannon_col] = "O"
board[guess_row_cannon][guess_col_cannon] = "O"
board[comp_row_archer][comp_col_archer] = "d"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_cannon_row][user_cannon_col] == "F":
                board[user_cannon_row][user_cannon_col] = "O"
board[guess_row_cannon][guess_col_cannon] = "O"
board[comp_row_grenade][comp_col_grenade] = "F"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_cannon_row][user_cannon_col] == "X" or board[user_cannon_row][user_cannon_col] == "O":
                board[user_cannon_row][user_cannon_col] = "C"
board[guess_row_cannon][guess_col_cannon] = "O"
guess_row_cannon = user_cannon_row
                guess_col_cannon = user_cannon_col
                set_home_position(board)
                print_board (board)
                x = True
elif board[user_cannon_row][user_cannon_col] == "h":
                print "Congratulations! You won the game!!!"
break
        if x == True:
            y = True
else:
            break
    elif the_choice == "Soldier" or the_choice == "soldier":
        x = False
while (x == False):
            user_soldier_row = int(raw_input ("Insert the new soldier row:"))
            user_soldier_col = int(raw_input ("Insert thew new soldier col:"))
            if board[user_soldier_row][user_soldier_col] == "G" or board[user_soldier_row][user_soldier_col] == "A" or board[user_soldier_row][user_soldier_col] == "g" or board[user_soldier_row][user_soldier_col] == "C" or board[user_soldier_row][user_soldier_col] == "S":
                print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_soldier_row) - int (guess_row_soldier)) == 1 and abs(int(user_soldier_col) - int(guess_col_soldier)) == 1:
                print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_soldier_row) - int (guess_row_soldier)) > 1 or abs(int(user_soldier_col) - int(guess_col_soldier)) > 1:
                print "invalid, sorry. Please re-enter position"
x = False
elif board[user_soldier_row][user_soldier_col] == "X":
                board[user_soldier_row][user_soldier_col] = "O"
board[guess_row_soldier][guess_col_soldier] = "O"
board[comp_row_soldier][comp_col_soldier] = "O"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_soldier_row][user_soldier_col] == "L":
                board[user_soldier_row][user_soldier_col] = "O"
board[guess_row_soldier][guess_col_soldier] = "O"
board[comp_row_general][comp_col_general] = "L"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_soldier_row][user_soldier_col] == "d":
                board[user_soldier_row][user_soldier_col] = "O"
board[guess_row_soldier][guess_col_soldier] = "O"
board[comp_row_archer][comp_col_archer] = "d"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_soldier_row][user_soldier_col] == "F":
                board[user_soldier_row][user_soldier_col] = "O"
board[guess_row_soldier][guess_col_soldier] = "O"
board[comp_row_grenade][comp_col_grenade] = "F"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_soldier_row][user_soldier_col] == "Y":
                board[user_soldier_row][user_soldier_col] = "O"
board[guess_row_soldier][guess_col_soldier] = "O"
board[comp_row_cannon][comp_col_cannon] = "Y"
set_home_position(board)
                print_board (board)
                x = True
elif board[user_soldier_row][user_soldier_col] == "O":
                board[user_soldier_row][user_soldier_col] = "S"
board[guess_row_soldier][guess_col_soldier] = "O"
guess_row_soldier = user_soldier_row
                guess_col_soldier = user_soldier_col
                set_home_position(board)
                print_board (board)
                x = True
elif board[user_soldier_row][user_soldier_col] == "h":
                print "Congratulations! You won the game!!!"
break
        if x == True:
            y = True
else:
            break
computer_the_choice = randint(0, 4)
    if computer_the_choice == 0:
        x = False
while (x == False):
            newcomp_general_row = randint (0, 9)
            newcomp_general_col = randint (0, 9)
            if board[newcomp_general_row][newcomp_general_col] == "L" or board[newcomp_general_row][newcomp_general_col] == "d" or board[newcomp_general_row][newcomp_general_col] == "F" or board[newcomp_general_row][newcomp_general_col] == "Y" or board[newcomp_general_row][newcomp_general_col] == "X":
                x = False
elif abs(int (newcomp_general_row) - int (comp_row_general)) == 1 and abs(int(newcomp_general_col) - int(comp_col_general)) == 1:
                x = False
elif abs(int (newcomp_general_row) - int (comp_row_general)) > 1 or abs(int(newcomp_general_col) - int(comp_col_general)) > 1:
                x = False
elif board[newcomp_general_row][newcomp_general_col] == "G":
                board[newcomp_general_row][newcomp_general_col] = "O"
board[comp_row_general][comp_col_general] = "O"
board[guess_row_general][guess_col_general] = "O"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_general_row][newcomp_general_col] == "A" or board[newcomp_general_row][newcomp_general_col] == "g" or board[newcomp_general_row][newcomp_general_col] == "C" or board[newcomp_general_row][newcomp_general_col] == "S" or board[newcomp_general_row][newcomp_general_col] == "O":
                board[newcomp_general_row][newcomp_general_col] = "L"
board[comp_row_general][comp_col_general] = "O"
comp_row_general = newcomp_general_row
                comp_col_general = newcomp_general_col
                set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_general_row][newcomp_general_col] == "H":
                print "Congratulations! You won the game!!!"
break
        if x == True:
            y = True
else:
            break
    elif computer_the_choice == 1:
        x = False
while (x == False):
            newcomp_archer_row = randint (0, 9)
            newcomp_archer_col = randint (0, 9)
            if board[newcomp_archer_row][newcomp_archer_col] == "L" or board[newcomp_archer_row][newcomp_archer_col] == "d" or board[newcomp_archer_row][newcomp_archer_col] == "F" or board[newcomp_archer_row][newcomp_archer_col] == "Y" or board[newcomp_archer_row][newcomp_archer_col] == "X":
                x = False
elif abs(int (newcomp_archer_row) - int (comp_row_archer)) == 1 and abs(int(newcomp_archer_col) - int(comp_col_archer)) == 1:
                x = False
elif abs(int (newcomp_archer_row) - int (comp_row_archer)) > 1 or abs(int(newcomp_archer_col) - int(comp_col_archer)) > 1:
                x = False
elif board[newcomp_archer_row][newcomp_archer_col] == "A":
                board[newcomp_archer_row][newcomp_archer_col] = "O"
board[comp_row_archer][comp_col_archer] = "O"
board[guess_row_archer][guess_col_archer] = "O"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_archer_row][newcomp_archer_col] == "G":
                board[newcomp_archer_row][newcomp_archer_col] = "O"
board[comp_row_archer][comp_col_archer] = "O"
board[guess_row_general][guess_col_general] = "G"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_archer_row][newcomp_archer_col] == "g" or board[newcomp_archer_row][newcomp_archer_col] == "C" or board[newcomp_archer_row][newcomp_archer_col] == "S" or board[newcomp_archer_row][newcomp_archer_col] == "O":
                board[newcomp_archer_row][newcomp_archer_col] = "d"
board[comp_row_archer][comp_col_archer] = "O"
comp_row_archer = newcomp_archer_row
                comp_col_archer = newcomp_archer_col
                set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_archer_row][newcomp_archer_col] == "H":
                print "Congratulations! You won the game!!!"
break
        if x == True:
            y = True
else:
            break
    elif computer_the_choice == 2:
        x = False
while (x == False):
            newcomp_grenade_row = randint (0, 9)
            newcomp_grenade_col = randint (0, 9)
            if board[newcomp_grenade_row][newcomp_grenade_col] == "L" or board[newcomp_grenade_row][newcomp_grenade_col] == "d" or board[newcomp_grenade_row][newcomp_grenade_col] == "F" or board[newcomp_grenade_row][newcomp_grenade_col] == "Y" or board[newcomp_grenade_row][newcomp_grenade_col] == "X":
                x = False
elif abs(int (newcomp_grenade_row) - int (comp_row_grenade)) == 1 and abs(int(newcomp_grenade_col) - int(comp_col_grenade)) == 1:
                x = False
elif abs(int (newcomp_grenade_row) - int (comp_row_grenade)) > 1 or abs(int(newcomp_grenade_col) - int(comp_col_grenade)) > 1:
                x = False
elif board[newcomp_grenade_row][newcomp_grenade_col] == "g":
                board[newcomp_grenade_row][newcomp_grenade_col] = "O"
board[comp_row_grenade][comp_col_grenade] = "O"
board[guess_row_grenade][guess_col_grenade] = "O"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_grenade_row][newcomp_grenade_col] == "G":
                board[newcomp_grenade_row][newcomp_grenade_col] = "O"
board[comp_row_grenade][comp_col_grenade] = "O"
board[guess_row_general][guess_col_general] = "G"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_grenade_row][newcomp_grenade_col] == "A":
                board[newcomp_grenade_row][newcomp_grenade_col] = "O"
board[comp_row_grenade][comp_col_grenade] = "O"
board[guess_row_archer][guess_col_archer] = "A"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_grenade_row][newcomp_grenade_col] == "C" or board[newcomp_grenade_row][newcomp_grenade_col] == "S" or board[newcomp_grenade_row][newcomp_grenade_col] == "O":
                board[newcomp_grenade_row][newcomp_grenade_col] = "F"
board[comp_row_grenade][comp_col_grenade] = "O"
comp_row_grenade = newcomp_grenade_row
                comp_col_grenade = newcomp_grenade_col
                set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_grenade_row][newcomp_grenade_col] == "H":
                print "Congratulations! You won the game!!!"
break
        if x == True:
            y = True
else:
            break
    elif computer_the_choice == 3:
        x = False
while (x == False):
            newcomp_cannon_row = randint (0, 9)
            newcomp_cannon_col = randint (0, 9)
            if board[newcomp_cannon_row][newcomp_cannon_col] == "L" or board[newcomp_cannon_row][newcomp_cannon_col] == "d" or board[newcomp_cannon_row][newcomp_cannon_col] == "F" or board[newcomp_cannon_row][newcomp_cannon_col] == "Y" or board[newcomp_cannon_row][newcomp_cannon_col] == "X":
                x = False
elif abs(int (newcomp_cannon_row) - int (comp_row_cannon)) == 1 and abs(int(newcomp_cannon_col) - int(comp_col_cannon)) == 1:
                x = False
elif abs(int (newcomp_cannon_row) - int (comp_row_cannon)) > 1 or abs(int(newcomp_cannon_col) - int(comp_col_cannon)) > 1:
                x = False
elif board[newcomp_cannon_row][newcomp_cannon_col] == "C":
                board[newcomp_cannon_row][newcomp_cannon_col] = "O"
board[comp_row_cannon][comp_col_cannon] = "O"
board[guess_row_cannon][guess_col_cannon] = "O"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_cannon_row][newcomp_cannon_col] == "G":
                board[newcomp_cannon_row][newcomp_cannon_col] = "O"
board[comp_row_cannon][comp_col_cannon] = "O"
board[guess_row_general][guess_col_general] = "G"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_cannon_row][newcomp_cannon_col] == "A":
                board[newcomp_cannon_row][newcomp_cannon_col] = "O"
board[comp_row_cannon][comp_col_cannon] = "O"
board[guess_row_archer][guess_col_archer] = "A"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_cannon_row][newcomp_cannon_col] == "g":
                board[newcomp_cannon_row][newcomp_cannon_col] = "O"
board[comp_row_cannon][comp_col_cannon] = "O"
board[guess_row_grenade][guess_col_grenade] = "g"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_cannon_row][newcomp_cannon_col] == "S" or board[newcomp_cannon_row][newcomp_cannon_col] == "O":
                board[newcomp_cannon_row][newcomp_cannon_col] = "Y"
board[comp_row_cannon][comp_col_cannon] = "O"
comp_row_cannon = newcomp_cannon_row
                comp_col_cannon = newcomp_cannon_col
                set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_cannon_row][newcomp_cannon_col] == "H":
                print "Congratulations! You won the game!!!"
break
        if x == True:
            y = True
else:
            break
    elif computer_the_choice == 4:
        x = False
while (x == False):
            newcomp_soldier_row = randint (0, 9)
            newcomp_soldier_col = randint (0, 9)
            if board[newcomp_soldier_row][newcomp_soldier_col] == "L" or board[newcomp_soldier_row][newcomp_soldier_col] == "d" or board[newcomp_soldier_row][newcomp_soldier_col] == "F" or board[newcomp_soldier_row][newcomp_soldier_col] == "Y" or board[newcomp_soldier_row][newcomp_soldier_col] == "X":
                x = False
elif abs(int (newcomp_soldier_row) - int (comp_row_soldier)) == 1 and abs(int(newcomp_soldier_col) - int(comp_col_soldier)) == 1:
                x = False
elif abs(int (newcomp_soldier_row) - int (comp_row_soldier)) > 1 or abs(int(newcomp_soldier_col) - int(comp_col_soldier)) > 1:
                x = False
elif board[newcomp_soldier_row][newcomp_soldier_col] == "S":
                board[newcomp_soldier_row][newcomp_soldier_col] = "O"
board[comp_row_soldier][comp_col_soldier] = "O"
board[guess_row_soldier][guess_col_soldier] = "O"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_soldier_row][newcomp_soldier_col] == "G":
                board[newcomp_soldier_row][newcomp_soldier_col] = "O"
board[comp_row_soldier][comp_col_soldier] = "O"
board[guess_row_general][guess_col_general] = "G"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_soldier_row][newcomp_soldier_col] == "A":
                board[newcomp_soldier_row][newcomp_soldier_col] = "O"
board[comp_row_soldier][comp_col_soldier] = "O"
board[guess_row_archer][guess_col_archer] = "A"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_soldier_row][newcomp_soldier_col] == "g":
                board[newcomp_soldier_row][newcomp_soldier_col] = "O"
board[comp_row_soldier][comp_col_soldier] = "O"
board[guess_row_grenade][guess_col_grenade] = "g"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_soldier_row][newcomp_soldier_col] == "C":
                board[newcomp_soldier_row][newcomp_soldier_col] = "O"
board[comp_row_soldier][comp_col_soldier] = "O"
board[guess_row_cannon][guess_col_cannon] = "C"
set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_soldier_row][newcomp_soldier_col] == "O":
                board[newcomp_soldier_row][newcomp_soldier_col] = "X"
board[comp_row_soldier][comp_col_soldier] = "O"
comp_row_soldier = newcomp_soldier_row
                comp_col_soldier = newcomp_soldier_col
                set_home_position(board)
                print_board (board)
                x = True
elif board[newcomp_soldier_row][newcomp_soldier_col] == "H":
                print "Congratulations! You won the game!!!"
break
        if x == True:
            y = True
else:
            break
    else:
        y = True

I2P-Bernard-Day8

Final Project Progress Report 3

  1. Screenshots.

So basically today I worked on my game hardcore. Everything is on track and I think it is 90% finished, took my around 5 hours today.

Screen Shot 2016-07-03 at 12.07.22 AM

Screen Shot 2016-07-03 at 12.07.36 AM

Screen Shot 2016-07-03 at 12.07.52 AM

Screen Shot 2016-07-03 at 12.08.03 AM

  1. Describe briefly what I’ve done.

Today, I finished up all my while loops and functions. As previously mentioned, there were many flaws in this game and today I limited a lot of them. I completed all the programming for the gameplay and also for the automated gameplay of the computer. This project was not as easy as I thought because in the beginning, when I was doing my Pecha Kucha, I thought this would not be that hard. However, programming this sort of action game was extremely challenging, but I enjoyed it. There were lots of difficulties and problems along the way. Such as using the “user_soldier_row” and “user_soldier_column” and “comp_row_grenade”. I had to test each one out and after a while I already felt dizzy. I currently have 718 lines of codes and this is because I did a lot of things the long way (since this is my first time coding an actual game). In this game, there are 5 figures (General, Archer, Grenade, Cannon, Soldier), and I have a set of code for each one. The good thing was that once I grasp the concept of 1 figure, then I could just reuse parts of that code for other figures. For example, as you can see in the screenshots above, there was a lot of repetition in while loops and for loops and if/else statements. I am sure there are shorter and faster ways but at the end of the day, my game works fine. One thing I added to my prototype that really enhanced my game was colour. While testing with my parents, they couldn’t tell the difference between the “user figures” and the “computer figures”. I came up with an idea of using colour but I had absolutely no idea how to execute it. So I did a lot of research online and luckily there were a few websites that provided the actual code for colour in Python. So I “borrowed” that code and used it in my program (as seen in the 3rd screenshot), and ultimately refined my prototype.

  1. A few lines of code with comments showing your understanding of the code.
elif the_choice == "Soldier" or the_choice == "soldier":
    x = False
while (x == False):
        user_soldier_row = int(raw_input ("Insert the new soldier row:"))
        user_soldier_col = int(raw_input ("Insert thew new soldier col:"))
        if board[user_soldier_row][user_soldier_col] == "G" or board[user_soldier_row][user_soldier_col] == "A" or board[user_soldier_row][user_soldier_col] == "g" or board[user_soldier_row][user_soldier_col] == "C" or board[user_soldier_row][user_soldier_col] == "S":
            print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_soldier_row) - int (guess_row_soldier)) == 1 and abs(int(user_soldier_col) - int(guess_col_soldier)) == 1:
            print "invalid, sorry. Please re-enter position"
x = False
elif abs(int (user_soldier_row) - int (guess_row_soldier)) > 1 or abs(int(user_soldier_col) - int(guess_col_soldier)) > 1:
            print "invalid, sorry. Please re-enter position"
x = False
elif board[user_soldier_row][user_soldier_col] == "X":
            board[user_soldier_row][user_soldier_col] = "O"
board[guess_row_soldier][guess_col_soldier] = "O"
board[comp_row_soldier][comp_col_soldier] = "O"
set_home_position(board)
            print_board (board)
            x = True
elif board[user_soldier_row][user_soldier_col] == "L":
            board[user_soldier_row][user_soldier_col] = "O"
board[guess_row_soldier][guess_col_soldier] = "O"
board[comp_row_general][comp_col_general] = "L"
set_home_position(board)
            print_board (board)
            x = True
elif board[user_soldier_row][user_soldier_col] == "d":
            board[user_soldier_row][user_soldier_col] = "O"
board[guess_row_soldier][guess_col_soldier] = "O"
board[comp_row_archer][comp_col_archer] = "d"
set_home_position(board)
            print_board (board)
            x = True
elif board[user_soldier_row][user_soldier_col] == "F":
            board[user_soldier_row][user_soldier_col] = "O"
board[guess_row_soldier][guess_col_soldier] = "O"
board[comp_row_grenade][comp_col_grenade] = "F"
set_home_position(board)
            print_board (board)
            x = True
elif board[user_soldier_row][user_soldier_col] == "Y":
            board[user_soldier_row][user_soldier_col] = "O"
board[guess_row_soldier][guess_col_soldier] = "O"
board[comp_row_cannon][comp_col_cannon] = "Y"
set_home_position(board)
            print_board (board)
            x = True
elif board[user_soldier_row][user_soldier_col] == "O":
            board[user_soldier_row][user_soldier_col] = "S"
board[guess_row_soldier][guess_col_soldier] = "O"
guess_row_soldier = user_soldier_row
            guess_col_soldier = user_soldier_col
            set_home_position(board)
            print_board (board)
            x = True
elif board[user_soldier_row][user_soldier_col] == "h":
            print "Congratulations! You won the game!!!"
  1. Other resources you came across in this learning process (e.g. a post from a discussion forum, an advice from your friends/classmates).

Used internet.

https://pypi.python.org/pypi/colored

http://matplotlib.org/examples/color/named_colors.html

I2P-Bernard-Day7

Final Project Progress Report 2

  1. Screenshots.

So basically I continued working on my game.

Here are some screenshots:

Screen Shot 2016-06-30 at 10.46.14 PM

Screen Shot 2016-06-30 at 10.46.19 PM

Screen Shot 2016-06-30 at 10.46.38 PM

  1. Describe briefly what I’ve done

Today, I made the functions even more complicated by adding more detail. When I first tried the beginning of the game yesterday, I realised that there were lots of flaws. I fixed them and one example would be by asking the user to input a number, every number must be different, therefore I had to make a code that inhibits them from entering the same number twice. There are many ways to do this but I used the while loop, for example,

while (x == False):
    guess_col_general = int(raw_input ("Insert general col:"))
    if hello[guess_row_general][guess_col_general] != "O":
        print "Sorry, this spot is already occupied"
x = False
else:
        x = True
hello[guess_row_general][guess_col_general] = "G"

My code currently stands at around 160 lines but I still needs a lot of work. Everything is going to plan and this first prototype I’m building now seems quite cool (I think). In the next few days, I will finish this prototype, adding more codes and functions, and hope to let some people play it, to get some feedback. I am very excited to see the final product and right now, I am currently around 40%-50% done.

  1. Other resources you came across in this learning process (e.g. a post from a discussion forum, an advice from your friends/classmates).

I reviewed the lessons on codecademy and used some YouTube videos.

I2P-Bernard-Day6

Final Project Progress Report 1

  1. Screenshots.

So basically I finished my Pecha Kucha and started my project.

Here are some screenshots:

Screen Shot 2016-06-29 at 5.23.36 PM

  1. Describe briefly what I’ve done

I basically created a game board and made a few functions. I just started and it needs A LOT more work. In detail, basically I used 5 functions to create the 5 figures on the game board. And use 5 more functions to create the computer 5 figures on the game board (this was part of my prototype in the Pecha Kucha). It took me a long time to figure out how to get the figures to show up on the game board. At last, I found out that I should use board [row][column], which allows me to input things into the bracket so the user can see the board after each turn during the gameplay. So far, everything is going according to my plan and my this first prototype, the one I mentioned in my Pecha Kucha, is already 30% done.

  1. Other resources you came across in this learning process (e.g. a post from a discussion forum, an advice from your friends/classmates).

I reviewed the lessons on codecademy and used some YouTube videos.

I2P-Bernard-Day(weekend sun)

Day Weekend Sun

  1. Describe briefly what you’ve done.

Today, I did the weekend mini-project (How to Travel to HKIS). Here are the screenshots:

Flow Chart I designed:

Screen Shot 2016-06-26 at 3.13.04 PM

The code on PyCharm Edu.

 

Screen Shot 2016-06-26 at 3.57.04 PM

  1. This is the code:

 

#this is the "How to Travel to HKIS Game"
#By:Bernard Luk

userchoice = raw_input ("Hi. Do you want to travel to HKIS? Yes or No?: ")
if userchoice == "No" or userchoice == "no":
    print "Then go away"
elif userchoice == "Yes" or userchoice == "yes":
    question1 = raw_input ("Do you have a driver? Yes or No?: ")
    if question1 == "Yes" or question1 == "yes":
        print "Then ask your driver to drive you to HKIS!"
elif question1 == "No" or question1 == "no":
        question2 = input("How much money do you have?: ")
        if question2 >= 80:
            print "Then take a Taxi, and ask him to drive you to HKIS"
elif question2 < 80:
            question3 = raw_input ("If there an MTR nearby? Yes or No?: ")
            if question3 == "No" or question3 == "no":
                print "Then take a bus. Before getting on a bus, make sure to check the bus route to see if there is Redhill, TaiTam"
elif question3 == "Yes" or question3 == "yes":
                question4 = raw_input ("Are you currently in Hong Kong Island? Yes or No?: ")
                if question4 == "No" or question4 == "no":
                    print "Look for the Island Line on the MTR. Then go to WanChai station. When you get to WanChai station, take the mini bus and get off at Red Hill, Tai Tam"
extra = raw_input ("Are you at HKIS? Yes or No?: ")
                    if extra == "Yes" or extra == "yes":
                        print "Yay!"
elif extra == "No" or extra == "no":
                        print "Oh Sorry. Not my fault"
else:
                        print "No idea what you're saying"
elif question4 == "Yes" or question4 == "yes":
                    print "Go to the WanChai station. When you get to WanChai station, take the mini bus and get off at Red Hill, Tai Tam"
question5 = raw_input ("Are you at HKIS? Yes or No?: ")
                    if question5 == "Yes" or question5 == "yes":
                        print "Yay!"
elif question5 == "No" or question5 == "no":
                        print "Oh Sorry. Not my fault"
else:
                        print "No idea what you're saying"
else:
                    print "No idea what you're saying"
else:
                print "No idea what you're saying"
else:
            print "No idea what you're saying"
else:
        print "No idea what you're saying"
else:
    print "No idea what you're saying"

 

 

I2P-Bernard-Day(weekend sat)

Day Weekend Sat

  1. Screenshots describing what you’ve completed on Codeacademy.

Screen Shot 2016-06-26 at 12.28.15 AM

Screen Shot 2016-06-26 at 12.28.23 AM

  1. Describe briefly what you’ve learnt.

Fo today, I only did JavaScript because I had to catch up on JS. I learned about objects and arrays. One thing that surprised me was that objects and arrays were kind of like dictionaries and lists in python.

  1. A few lines of code with comments showing your understanding of the code.

function Rabbit(adjective) {
this.adjective = adjective;
this.describeMyself = function() {
console.log(“I am a ” + this.adjective + ” rabbit”);
};
}

  1. Other resources you came across in this learning process (e.g. a post from a discussion forum, an advice from your friends/classmates).

I used a YouTube video. https://www.youtube.com/watch?v=rLKvhPcp1ps

I2P-Bernard-Day5

Day 5

  1. Screenshots describing what you’ve completed on Codeacademy.

Screen Shot 2016-06-25 at 12.06.44 AM

Screen Shot 2016-06-25 at 12.06.48 AM

 

Screen Shot 2016-06-25 at 12.09.01 AM

 

  1. Describe briefly what you’ve learnt.

For Python, I learned about for and while loops. I also had a chance to practice and apply them.

For JavaScript, I learned about arrays and objects (just an introduction). I also learned how to use a handy tool called the switch.

  1. A few lines of code with comments showing your understanding of the code.

Python:

def print_grades(grades):
for grade in grades:
print grade

def grades_sum(grades):
total = 0
for grade in grades:
total += grade
return total

def grades_average(grades):
sum_of_grades = grades_sum(grades)
average = sum_of_grades / float(len(grades))
return average

def grades_variance(scores):
average = grades_average(scores)
variance = 0
for score in scores:
variance = variance + (average – score) ** 2
variance = variance / len(scores)

JavaScript:

switch(color) {
case ‘red’:
console.log(“Red’s a good color!”);
break;
case ‘blue’:
console.log(“That’s my favorite color, too!”);
break;
case “yellow”:
console.log(“That’s my favorite yellow color, too!”);
break
default:
console.log(“I don’t think that’s a primary color!”);

  1. Other resources you came across in this learning process (e.g. a post from a discussion forum, an advice from your friends/classmates).

I used the YouTube videos provided in the Schoology page made by Mr. Lin.

I2P-Bernard-Day4

Day 4

  1. Screenshots describing what you’ve completed on Codeacademy.

Screen Shot 2016-06-23 at 11.40.54 PM

Screen Shot 2016-06-23 at 11.40.58 PM

  1. Describe briefly what you’ve learnt.

For today, I didn’t have enough time to finish 2 lessons on Python. I will catch up more on Javascript tomorrow.

For Python, I learned how to incorporate lists and functions together. And also iterating over a list in a function.

  1. A few lines of code with comments showing your understanding of the code.

def total (numbers):
result = 0
for digit in numbers:
result = result + digit
return result

and

if guess_row == ship_row and guess_col == ship_col:
print “Congratulations! You sunk my battleship!”
break
else:
if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4):
print “Oops, that’s not even in the ocean.”
elif(board[guess_row][guess_col] == “X”):
print “You guessed that one already.”
else:
print “You missed my battleship!”
board[guess_row][guess_col] = “X”
if turn == 3:
print “Game Over”

  1. Other resources you came across in this learning process (e.g. a post from a discussion forum, an advice from your friends/classmates).

I used a YouTube video to help me. https://www.youtube.com/watch?v=7Ki_2gr0rsE

I2P-Bernard-Day3

Day 3

  1. Screenshots describing what you’ve completed on Codeacademy.

Screen Shot 2016-06-22 at 11.34.33 PM

Screen Shot 2016-06-22 at 11.35.05 PM

Screen Shot 2016-06-22 at 11.35.11 PM

  1. Describe briefly what you’ve learnt.

Today, I completed Unit 5 of Python and I also completed Unit 4 in Javascript. I am a bit behind schedule but will try my best to catch up (because I also have a day course at school).

For Python, I learned how to apply Lists and Dictionaries. For example in the activity where I had to create a supermarket calculator.

For JavaScript, I learned how to use while loops and do while loops. I also learned how to apply it to different context in the activity, “Dragon Slayer!”.

  1. A few lines of code with comments showing your understanding of the code.

Python:

def compute_bill(food):
total = 0
for key in food:
if stock[key] > 0:
total = total + prices[key]
stock[key] = stock[key] – 1
return total

JavaScript:

while (slaying) {
if (youHit) {
console.log(“You hit the dragon and did ” + damageThisRound + ” damage!”);
totalDamage += damageThisRound;

 

  1. Other resources you came across in this learning process (e.g. a post from a discussion forum, an advice from your friends/classmates).

I used a YouTube video to help me. https://www.youtube.com/watch?v=HS4iN4-SdHo

I2P-Bernard-Day2

Day 2

  1. Screenshots describing what you’ve completed on Codeacademy.

Screen Shot 2016-06-21 at 10.05.44 PM

Screen Shot 2016-06-21 at 10.05.49 PM

Screen Shot 2016-06-21 at 10.08.24 PM

  1. Describe briefly what you’ve learnt.

For Python, I learned how to use functions and I coded a small tool on Codecademy called “Taking a Vacation”. I also learned about Python lists and dictionaries, it was a little confusing but I used outside resources such as a YouTube video to help me.

For JavaScript, I mainly learned how to use “for loops”. It took me a while to understand the concept thats why I didn’t reach my goal of completing Unit 3. I will definitely finish this unit tomorrow.

  1. A few lines of code with comments showing your understanding of the code.

Python:

del zoo_animals[‘Sloth’]
del zoo_animals[‘Bengal Tiger’]
zoo_animals[‘Rockhopper Penguin’] = ‘Jungle House’

 

JavaScript:

var cities = [“Melbourne”, “Amman”, “Helsinki”, “NYC”, “HK”];

for (var i = 0; i < cities.length; i++) {
console.log(“I would like to visit ” + cities[i]);

  1. Other resources you came across in this learning process (e.g. a post from a discussion forum, an advice from your friends/classmates)

I used a YouTube video to help me. https://www.youtube.com/watch?v=6EtDsfxGv5Q