My teacher is making us do an old ACSL program for practice, and he said that we can use any resources we want. The program is from 2013. link here: https://s3.amazonaws.com/iedu-attachments-question/5a989d787772b7fd88c063aff8393d34_1bee2d300c35eec13edf0a3af515a5a5.pdf
We started the program, but we ran into a wall, and we don't know what to do from here:
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]
]
for i in range(1, 6):
pieces = input("%d. "%(i)).split(",")
white = []
black = []
black_start = int(pieces[0])+1
for j in range(1, black_start):
white.append(int(pieces[j]))
for k in range(black_start+1, len(pieces)):
black.append(int(pieces[k]))
print(white)
print(black)
for pair in board:
can anyone give us some tips? we are coding in Python.
I don't think
board
actually serves any purpose.Your code for parsing input to black and white piece-locations looks good, and should probably be made into a function.
For debugging, it would be useful to have a function which takes black and white piece-locations and prints the board - for example using the characters
#
for black,O
for white, and.
for empty. This will help you to see what your program is doing.For each direction, you should have a function (ie
left
) which returns the next location (orNone
if it is on the edge of the board) and another (ieleft_lst
) which returns a list of consecutive locations in that direction. Soleft(17)
returns16
,left(16)
returnsNone
, andleft_lst(19)
returns[18, 17, 16]
. Hint: how can you implementleft_lst
in terms ofleft
?Then: for each white piece, check what can be captured by moving toward each direction or away from each direction. You know that there should only be one solution, so as soon as you find it you can return it; if you do not find any, return
None
.Hope that helps!
For fun and interest, here's the solution I came up with. Hope you learn lots!