代写0CCS0CSE、代做Python编程设计
Introduction to CS & Engineering (0CCS0CSE)
Homework
Due Friday Feb. 7
th
, 11am
Activity
Chess is a two-player board game, played on a chequered board where pieces are moved
according to precise rules (see Table 1). The object of the game is to attack the opponent’s
king in such a way that escape is impossible (checkmate). Each square on a chess board
can be described by a letter (file) and number (rank). For example, in Figure 1, square
b4 is on file b and rank 4.
Figure 1: Chess board positions. (www.logicalchess.com)
For this homework assignment you will design and implement two functions. The first
function, position(piece, loc), takes the name of a chess piece and its position, and
returns all the squares that piece can reach after a single move is made. The second
function, getTo(piece, loc1, loc2), takes the name of a chess piece, two positions,
and returns true if the piece can reach the second position in exactly two moves. Assume
there are no other pieces on the board.
1Chess Pieces
Piece Moves
King Moves one square in any direction.
Queen Any number of squares diagonally, horizontally, or vertically.
Rook Any number of squares horizontally or vertically.
Bishop Any number of squares diagonally.
Knight In an ‘L-shape,’ two squares in a straight direction, and
then one square perpendicular to that.
Pawn One square forward
Table 1: Valid piece names and a description of how they move.
Requirements
1. The program should contain at least 3 functions. Furthermore, it should demonstrate
an understanding how and when to use functions.
2. The program must contain and use the functions position(piece, loc) and getTo(piece,
loc1, loc2)
3. The program should be written without using the chr() function, the ord() function,
tuples, list comprehension, or nested functions (i.e., closures & decorators)
4. All of your code should be within a function, i.e., no global variables
5. Follow all submission requirements
position(piece, loc)
1. The function accepts full piece names, e.g., King, Rook or Queen, as a string. The
function should be case insensitive, that is, King, king, and KING are treated the
same.
2. The function should accept positions, as a string, in file-rank format, e.g., b5, h8 or
f3. The function should be case insensitive, that is, b3 and B3 are treated same.
3. The function should return a list; the order of the chess squares in the list does not
matter.
4. If an invalid piece is passed to the function, i.e., a piece not found in Table 1, the
function should return an empty list
5. If the position of the piece is invalid, the function should return an empty list
6. If the piece is in a position where it has no valid moves, the function should return
an empty list
2getTo(piece, loc1, loc2)
1. The function accepts full piece names, e.g., King, Rook or Queen, as a string. The
function should be case insensitive, that is, King, king, and KING are treated the
same.
2. The function should accept positions, as a string, in file-rank format, e.g., b5, h8 or
f3. The function should be case insensitive, that is, b3 and B3 are treated same.
3. The function should return True or False. If the piece can get from position 1
to position 2 in exactly two moves, the function should return True, otherwise it
should return False.
4. If the piece can get from position 1 to position 2 in one move, return False
5. If the piece is already on position 2, return False
6. The function must use the position(piece, loc) function appropriately.
Sample Test Cases
For testing purposes, here are some of the test cases your submission must pass.
1 position ('King ', 'f3 ')
2 # Returns ['e4 ','f4 ','g4 ','e3 ','g3 ','e2 ','f2 ','g2 ']
3
4 position ('Rook ','i4 ')
5 # Returns []
6
7 position ('knight ','d4 ')
8 # Returns ['e6 ','f5 ','f3 ','e2 ','b3 ','c2 ','b5 ','c6 ']
9
10 getTo ('king ', 'e1 ', 'e3 ')
11 # Returns True
12
13 getTo ('pawn ', 'c2 ', 'c8 ')
14 # Returns False
15
16 getTo ('knight ', 'g1 ', 'e5 ')
17 # Returns True
3Submission Instructions
Failure to follow all submission instructions may result in a lower grade.
1. At the top of your program put the following comments:
# [Your Full Name]
# [Your K number]
# Homework 1
2. Name your solution hw1.py —exactly as you see it here. One word all lowercase,
with the *.py extension.
3. Submit the Python file (*.py) on KEATS —You do not need to include a cover
sheet
4. If asked for a submission title, enter your full name.
Marking
The mark is split 60% functionality and 40% implementation. Meaning, if your program
works and passes all test cases you automatically get a 60. The remaining 40% will be
given based on how well you implemented your solution., e.g., appropriate use of functions,
use of descriptive variable names, following submission instructions, and meeting
program requirements.
Note:
• if your program crashes during testing, you will receive a 40 regardless
of the error that caused the crash
• if your program uses any of the following, chr() function, the ord() function,
tuples, list comprehension, or nested functions (i.e., closures & decorators),
you will receive a zero
• any submission that significantly deviates from the assignment will receive
a zero.
Rubric for Implementation
• Requirements. All specified requirements have been met (15 points)
• Functions. The solution demonstrates good use of functions; the code is reusable;
the code is efficient without sacrificing readability; and the solution is well organised
and easy to understand (15 points)
• Variable & function names. The solution uses meaningful identifier names, i.e.,
good function and variables names (5 points)
• Comments. The solution contains function level comments; few in-line comments
are used; and comments do not make code difficult to read/understand (5 points)
4Late Submission Policy
All coursework must be submitted on time. If you submit coursework late and have not
applied for an extension or have not had a mitigating circumstances claim upheld, you
will have an automatic penalty applied. If you submit late, but within 24 hours of the
stated deadline, the work will be marked, and 10 raw marks will be deducted. All work
submitted more than 24 hours late will receive a mark of zero.
• Any program submitted within 24 hours after the deadline will lose 10 points
• Any program submitted after the 24 hour grace period will receive a 0
5

热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图