Question

# In this file, fill in the ... parts with lines of code. Do not
# create new functions.

from random import seed, randrange
P=[" ♟♜♝♞♛♚"]; L,R,BL,TL=["▌▐▄▀"]
BonR=WonR=WonB=DonR=DonB=RonB=GonR=GonB=RonG='\033[1;m\033['
WonR+='7;31;47m' # For drawing a white piece on a red background
WonB+='7;30;47m' # For drawing a white piece on a black background
DonR+='2;37;41m' # For drawing a dark piece on a red background
DonB+='2;37;40m' # For drawing a dark piece on a black background
GonR+='2;33;41m' # For drawing gold on a red background
GonB+='2;33;40m' # For drawing gold on a black background
RonG+='2;31;43m' # For drawing red on a gold background
RonB+='7;30;41m' # For drawing red on a black background
BonR+='0;30;41m' # For drawing black on a red background

def Black(x,w,c):
if(c==0):
print(GonB,R)
if(w==1):
print(WonB,x)
else:
print(DonB,x)
if(c==7):
print(GonB,L)
  
  
"""A function to print a chess piece on a black background.
Inputs:
x: A single-character string indicating the value to put in
this square. It will be one of the following: " ", "♟",
"♜", "♝", "♞", "♛", or "♚". (Note that " " is one of the
options, and is used for empty squares.)
w: A boolean value indicating whether this is a white piece.
c: An integer indicating the column of this square. (We need
to know this because the leftmost square (c=0) has gold
on the left side, and the rightmost square (c=7) has gold
on the right side.

Outputs:
-To begin, in the one case that c=0, 3 spaces are printed.
-Next, regardless of c's value, the one character passed in
as x is printed, in the indicated color.
-Finally, in the one case that c=7, a newline character is
printed. """
'''
BonR=WonR=WonB=DonR=DonB=RonB=GonR=GonB=RonG='\033[1;m\033['
WonR+='7;31;47m' # For drawing a white piece on a red background
WonB+='7;30;47m' # For drawing a white piece on a black background
DonR+='2;37;41m' # For drawing a dark piece on a red background
DonB+='2;37;40m' # For drawing a dark piece on a black background
GonR+='2;33;41m' # For drawing gold on a red background
GonB+='2;33;40m' # For drawing gold on a black background
RonG+='2;31;43m' # For drawing red on a gold background
RonB+='7;30;41m' # For drawing red on a black background
BonR+='0;30;41m' # For drawing black on a red background
'''
def Red(x,w,c):
if(c==0):
print(GonR,R)
if(w==1):
print(WonR,x)
else:
print(DonR,x)
if(c==7):
print(GonR,L)
  
"""A function to print a chess piece on a red background.
Inputs: These are the same as the inputs for Black()
x: A string indicating the value to put in this square.
w: A boolean value indicating whether this is a white piece.
c: An integer indicating the column of this square.

Outputs:
-To begin, in the one case that c=0, 3 spaces are printed.
-Next, regardless of c's value, three characters always print:
1: A "▐" character that is red on its right side, and that
is either gold (if c=0) or black (otherwise) on its left
side.
2: The character passed in as x, in the indicated color.
3: A "▌" character that is red on its left side and that is
either gold (if c=7) or black (otherwise) on its right
side.
-Finally, in the one case that c=7, a newline is printed.
But somethings needs to be understood here. First, you don't
really need to print a "\n", you can just NOT use an "end=''"
when printing this last "▌" piece. Second, you also need to
change the color to GonB before going to the next line, to
prevent colored bars from drawing on the left. """

def DrawBoard(B,W):
for i in range(0,8):
DrawRow(i,B,W)
"""A function to draw a chess board with its pieces.
Inputs:
B: This is the board. It must be a list of 8 strings, which
indicate the 8 rows of the chessboard. The 8 strings are
each 8 characters wide, indicating the 8 rows of the
chessboard. The individual characters in the strings are
any of the following: " ","♟","♜","♝","♞","♛", or "♚".
W: This is a list of 16 complex numbers. Each number encodes
the row/column position of one of the 16 white pieces.
(We don't need a similar list of dark pieces, because
anything that is not white can print as dark.

Outputs:
The output is to print the eight rows of the board, along
with two more rows for the top and bottom gold border. """

def DrawRow(r,B,W):
"""A function to draw a single row of the chess board.
Input:
r: An integer indicating the row number.
B: This is the board.
W: This is a list of white piece locations.

Outputs:
The output is the printing of the indicated row. """
if i in range (0,8):
if ((r+i)%2==0):
if complex(r,i) in W:
Black(B[r][i],1,i)
else:
Black(B[r][i],0,i)
else:
if complex(r,i) in W:
Red(B[r][i],1,i)
else:
Red(B[r][i],0,i)
  
  

def DrawAnInitialBoard():
# P=" ♟♜♝♞♛♚"; L,R,BL,TL="▌▐▄▀"   
B=[]
temp1=P[2]+P[3]+P[4]+P[5]+P[6]+P[4]+P[3]+P[2]
temp2=P[1]*8
temp3=P[0]*8
B=[temp1,temp2,temp3,temp3,temp3,temp3,temp2,temp1]
  
W=[]
for i in range(6,8):
for j in range(0,7):
temp=complex(i,j)
W+=[temp]
  
  
"""A function to create and draw an initial board. This means the
board is: ["♜♝♞♛♚♞♝♜","♟♟♟♟♟♟♟♟"," "," ",
" "," ","♟♟♟♟♟♟♟♟","♜♝♞♛♚♞♝♜"].
and it also means that the white pieces are in the last two
rows.

But I have RULES for you to follow.
1. You cannot use any string quotes and you cannot call the
str function in your implementation. I am making this rule
to give you experience with slicing and string operators.
I want to point out that the P string holds the symbols
that you need.
(I also want to point out that you should *start* by using
the above-provided 8 strings for your board. Only after
you get that working should you then create again the list
of strings, but this time without using quotes.)
2: Try to use as few characters as possible to implement this
function. I will grade on based on how few characters you
use (ignoring spaces, tabs, and newlines). My solution
uses 102 characters. """


DrawAnInitialBoard()
  
def DrawRandomBoard():
for i in range(0,8):
  
def RandomPlacement(color,otherColor):
i=0
while i<16:
temp=complex(randrange(8),randrange(8))
if temp not in otherColor:
color+=[temp]
i+=1
  
  
"""A function to create and draw a board with all 32 pieces in
random positions. """

#Comment this line to make it run differently each time
  
W=[];D=[];B=[] #This B object is the board.
RandomPlacement(W, D)
RandomPlacement(D, W)
# Now that we know where the pieces go, we need to create the
# eight rows of the board, inserting pieces into those spots.
# Here, it does not matter how you decide to map the 16 pieces
# of each color to the 16 positions in the W or D lists.
chess=P[2]+P[3]+P[4]+P[5]+P[6]+P[4]+P[3]+P[2]+P[1]*8
con =0
for i in range(0,8):

a=""
for j in range(0,8):
if (complex(i,j) in W or complex(i,j ) in D):
a+=chess[con%16]
con+=1
else:
a+=P[0]
if j==7:
B+=[a]
DrawBoard(B,W)
DrawRandomBoard()
  
  
  
  

              
               % python3 PAL.py o ( 0 0

This is an colored chessboard written in Python. The annotations are explanation on the function.

But this is not working, how to fix?


 
0 0
Add a comment Improve this question Transcribed image text
Answer #1

- he Valla ble hile declaring น. The (0mpiky will-And -the of -the variable -Poim -fhe valiue ass eu ee to declare a ing

Add a comment
Know the answer?
Add Answer to:
# In this file, fill in the ... parts with lines of code. Do not # create new functions. from ran...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end show the exact Output that's shown in the Problem 2. CODE PROVIDED FOR PROBLEM 1: import java.util.Scanner; public class Problem1 {    public static void main( String [] args )    {        //N denoting the size of the board        int...

  • Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end, show the exact Output that's shown in Problem 2. CODE PROVIDED FOR PROBLEM 1: import java.util.Scanner; public class Problem1 {    public static void main( String [] args )    {        //N denoting the size of the board        int n;       ...

  • Must be done in Java. PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. PROBLEM 1 INFORMATION IF YOU NEED IT AS WELL: Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end, show the exact Output that's shown in Problem3. CODE PROVIDED FOR PROBLEM 2: import java.util.Scanner; public class Problem2 { public static void main( String [] args ) { //N...

  • Please develop the following code using C programming and using the specific functions, instructi...

    Please develop the following code using C programming and using the specific functions, instructions and format given below. Again please use the functions given especially. Also don't copy any existing solution please write your own code. This is the first part of a series of two labs (Lab 7 and Lab 8) that will complete an implementation for a board-type game called Reversi (also called Othello). The goal of this lab is to write code that sets up the input...

  • Using the template code provided in the braille translator.py file as a starting point, complete functions...

    Using the template code provided in the braille translator.py file as a starting point, complete functions enocode and decode that convert alphabets back and forth between normal English and English Braille. OOOOOOOO. • • • mn Op W X Y Z (Modified from: https://en.wikipedia.org/wiki/English_Braille) Figure 1: The various Braille alphabets. The above table shows the various Braille alphabets corresponding to English alphabets a-z. Each Braille alphabet is represented as a 3 x 2 matrix (three rows and two columns). The...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

  • how do I write this code without the imports? I don't know what pickle is or...

    how do I write this code without the imports? I don't know what pickle is or os.path import pickle # to save and load history (as binary objects) import os.path #to check if file exists # character value mapping values = {'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8, 'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, ' S': 1,...

  • Notes for lab dc02-Resistors and the Color Code will skip are Part 2 e, g: Part 4; Exercises 2, 4,5,6 an...

    Notes for lab dc02-Resistors and the Color Code will skip are Part 2 e, g: Part 4; Exercises 2, 4,5,6 and 3. It is important to answer the exercises correctly in each labl you should include the appropriate prefix for the unit in the Numerical Value We will not be Volt using the Volt-Ohm meter (VOM) for this lab, so skip the parts that ask for VOM measurements. The parts we You do need to complete Exercises1 Note that in...

  • Game Description: Most of you have played a very interesting game “Snake” on your old Nokia...

    Game Description: Most of you have played a very interesting game “Snake” on your old Nokia phones (Black & White). Now it is your time to create it with more interesting colors and features. When the game is started a snake is controlled by up, down, left and right keys to eat food which appears on random locations. By eating food snake’s length increases one unit and player’s score increases by 5 points. Food disappears after 15 seconds and appears...

  • 1. Fill out the following table by indicating which general technique (light microscopy (LM) or electron...

    1. Fill out the following table by indicating which general technique (light microscopy (LM) or electron microscopy (EM]) could be used to observe each structure or phenomenon. Put "no" in the box if the technique could not be used. If light microscopy can be used, name one technique (bright-field, phase-contrast, fluorescence, etc.) that you think would be effective. You will find some useful information in Appendix 1 of this manual and Chapter 18 of your textbook. Structure or phenomenon Could...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT