Here is what I have so far:
def printBoard(board):
printBoard = ['','','','','','','','']
for k in range(0, 8):
for i in range(0,8):
printBoard[i] += board[i][k] #k and i may be subject to switch
for row in printBoard:
print(row)
print('')
letters2nums = {'a':0,'b':1,'c':2,'d':3,'e':4,'f':5,'g':6,'h':7}
rows = []
addRow = [' -- ',' -- ',' -- ',' -- ',' -- ',' -- ',' -- ',' -- ',' -- ']
for i in range(0,8):
rows = rows + [addRow]
rows[0] = [' br ', ' bn ', ' bb ', ' bq ', ' bk ', ' bb ', ' bn ', ' br ']
rows[1] = [' bp ',' bp ',' bp ',' bp ',' bp ',' bp ',' bp ',' bp ']
rows[6] = [' wp ',' wp ',' wp ',' wp ',' wp ',' wp ',' wp ',' wp ']
rows[7] = [' wr ', ' wn ', ' wb ', ' wq ', ' wk ', ' wb ', ' wn ', ' wr ']
printBoard(rows)
print("Your turn!")
print("First, enter the square of the piece you'd like to move.")
print("Then, enter the square of the place you'd like to move your piece to.")
moveLegal = False
while moveLegal == False:
part1 = input("Part 1:")
part2 = input("Part 2:")
print(rows[8-int(part1[1])][letters2nums[part1[0]]][1])
if rows[8-int(part1[1])][letters2nums[part1[0]]][1] == 'w' and not rows[8-int(part2[1])][letters2nums[part2[0]]][1] == 'w':
piece = rows[8-int(part1[1])][letters2nums[part1[0]]]
currRow = 8-int(part1[1])
currClmn = letters2nums[part1[0]]
futureRow = 8-int(part2[1])
futureClmn = letters2nums[part2[0]]
moveLegal = True
(rows[futureRow])[futureClmn] = piece
rows[currRow][currClmn] = ' -- '
printBoard(rows)Let's say you first enter e2, then e4. For some reason it prints the pawn 2 times. Please help!!!
Offline
Insert a line of code that makes the pawn disappear when you add in a new line for it.
I don't know python, but example:
(imput1 is e2 in your example)
if[piece position]=[input1], [piece position]=[empty]
Offline
cpumaster930 wrote:
Shouldn't this go in Advanced Topics?
![]()
No, because it doesn't have anything to do with Scratch.
Offline
randomnumber53 wrote:
cpumaster930 wrote:
Shouldn't this go in Advanced Topics?
![]()
No, because it doesn't have anything to do with Scratch.
It's about Python, an advanced programming language, and there's a lot of PHP and MySQL stuff in Advanced Topics that don't really relate to Scratch (aside from certain APIs made by sparks
)
Offline
cpumaster930 wrote:
randomnumber53 wrote:
cpumaster930 wrote:
Shouldn't this go in Advanced Topics?
![]()
No, because it doesn't have anything to do with Scratch.
It's about Python, an advanced programming language, and there's a lot of PHP and MySQL stuff in Advanced Topics that don't really relate to Scratch (aside from certain APIs made by sparks
)
It's okay to put non-Scratch stuff in Advanced Topics. This would be a good fit for that forum. Use the Report to ask a Community Moderator to move it there, if you like
Offline
bump
Offline
bump???
Offline
FOUND IT!!!
(whoa, that took long time....)
this should do the job:
def printBoard(board):
printBoard = ['']*8
for k in range(0, 8):
for i in range(0,8):
printBoard[i] += board[i][k] #k and i may be subject to switch
for row in printBoard:
print(row)
print('')
letters2nums = {'a':0,'b':1,'c':2,'d':3,'e':4,'f':5,'g':6,'h':7}
rows = [0]*8
for i in range(0,8):
rows[i] = [' -- '] * 8
rows[0] = [' br ', ' bn ', ' bb ', ' bq ', ' bk ', ' bb ', ' bn ', ' br ']
rows[1] = [' bp ',' bp ',' bp ',' bp ',' bp ',' bp ',' bp ',' bp ']
rows[6] = [' wp ',' wp ',' wp ',' wp ',' wp ',' wp ',' wp ',' wp ']
rows[7] = [' wr ', ' wn ', ' wb ', ' wq ', ' wk ', ' wb ', ' wn ', ' wr ']
printBoard(rows)
print("Your turn!")
print("First, enter the square of the piece you'd like to move.")
print("Then, enter the square of the place you'd like to move your piece to.")
moveLegal = False
while moveLegal == False:
part1 = input("Part 1:")
part2 = input("Part 2:")
print(rows[8-int(part1[1])][letters2nums[part1[0]]][1])
if rows[8-int(part1[1])][letters2nums[part1[0]]][1] == 'w' and not rows[8-int(part2[1])][letters2nums[part2[0]]][1] == 'w':
currRow = 8-int(part1[1])
currClmn = letters2nums[part1[0]]
futureRow = 8-int(part2[1])
futureClmn = letters2nums[part2[0]]
piece = rows[currRow][currClmn]
moveLegal = True
rows[futureRow][futureClmn] = piece
rows[currRow][currClmn] = ' -- '
printBoard(rows)the problem was, you linked rows to a link (addRow in your code) instead of direct linking to the object ( which was [' -- ', ' -- ', ' -- ', ' -- ', ' -- ', ' -- ', ' -- ', ' -- ']), so once you changed one line, all the others got also changed
Offline
WaterHorse wrote:
what is that?
python is a porgammin language
Offline
spike111 wrote:
make a line of code that deletes the printed pawn on e3
it's solved -.-
Offline