This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-09-07 22:22:45

randomnumber53
Scratcher
Registered: 2010-05-19
Posts: 500+

Help with my Python Chess

Here is what I have so far:

Code:

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!!!


http://i1095.photobucket.com/albums/i477/randomnumber53/addForSig.png
http://www.prguitarman.com/icon/poptartFINALTINY.gif`·.,¸,.·*¯`·.,¸,.·*¯[;::;‹]ᵒᴥᵒ­­­­­­­­­­)  Don't forget to add the +KITTENS

Offline

 

#2 2011-09-08 08:09:37

helltank
Scratcher
Registered: 2010-05-21
Posts: 1000+

Re: Help with my Python Chess

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]


Error:Signature could not load. Please wait for an indefinite amount of time, until you realize you're gullible and go off to look for another potentially interesting signature to stare at.

Offline

 

#3 2011-09-08 08:40:52

WaterHorse
Scratcher
Registered: 2008-10-19
Posts: 500+

Re: Help with my Python Chess

what is that?


Horses rock my world! <3
http://www.weebly.com/uploads/1/0/1/4/10146167/5225297_orig.pnghttp://www.weebly.com/uploads/1/0/1/4/10146167/2294523_orig.png

Offline

 

#4 2011-09-08 15:35:39

cpumaster930
Scratcher
Registered: 2009-02-23
Posts: 100+

Re: Help with my Python Chess

Shouldn't this go in Advanced Topics?  wink


http://i.imgur.com/Qd0lu.png

Offline

 

#5 2011-09-08 16:57:03

randomnumber53
Scratcher
Registered: 2010-05-19
Posts: 500+

Re: Help with my Python Chess

cpumaster930 wrote:

Shouldn't this go in Advanced Topics?  wink

No, because it doesn't have anything to do with Scratch.


http://i1095.photobucket.com/albums/i477/randomnumber53/addForSig.png
http://www.prguitarman.com/icon/poptartFINALTINY.gif`·.,¸,.·*¯`·.,¸,.·*¯[;::;‹]ᵒᴥᵒ­­­­­­­­­­)  Don't forget to add the +KITTENS

Offline

 

#6 2011-09-08 16:58:23

cpumaster930
Scratcher
Registered: 2009-02-23
Posts: 100+

Re: Help with my Python Chess

randomnumber53 wrote:

cpumaster930 wrote:

Shouldn't this go in Advanced Topics?  wink

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  tongue )


http://i.imgur.com/Qd0lu.png

Offline

 

#7 2011-09-08 18:02:22

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Help with my Python Chess

cpumaster930 wrote:

randomnumber53 wrote:

cpumaster930 wrote:

Shouldn't this go in Advanced Topics?  wink

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  tongue )

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  smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#8 2011-09-10 18:23:33

randomnumber53
Scratcher
Registered: 2010-05-19
Posts: 500+

Re: Help with my Python Chess

bump


http://i1095.photobucket.com/albums/i477/randomnumber53/addForSig.png
http://www.prguitarman.com/icon/poptartFINALTINY.gif`·.,¸,.·*¯`·.,¸,.·*¯[;::;‹]ᵒᴥᵒ­­­­­­­­­­)  Don't forget to add the +KITTENS

Offline

 

#9 2011-09-11 13:27:38

randomnumber53
Scratcher
Registered: 2010-05-19
Posts: 500+

Re: Help with my Python Chess

bump???


http://i1095.photobucket.com/albums/i477/randomnumber53/addForSig.png
http://www.prguitarman.com/icon/poptartFINALTINY.gif`·.,¸,.·*¯`·.,¸,.·*¯[;::;‹]ᵒᴥᵒ­­­­­­­­­­)  Don't forget to add the +KITTENS

Offline

 

#10 2011-09-12 12:28:51

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: Help with my Python Chess

python version? (2/3)

EDIT: never mind, found out  smile  (raw_input/input thing)
looking at your script now..

Last edited by roijac (2011-09-12 12:49:19)

Offline

 

#11 2011-09-12 13:27:04

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: Help with my Python Chess

FOUND IT!!!
(whoa, that took long time....)

this should do the job:

Code:

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  smile

Offline

 

#12 2011-09-20 09:40:29

spike111
Scratcher
Registered: 2010-12-16
Posts: 24

Re: Help with my Python Chess

make a line of code that deletes the printed pawn on e3

Offline

 

#13 2011-09-20 10:00:19

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Help with my Python Chess

WaterHorse wrote:

what is that?

python is a porgammin language


Posts: 20000 - Show all posts

Offline

 

#14 2011-09-20 10:04:30

roijac_test
Scratcher
Registered: 2011-08-31
Posts: 49

Re: Help with my Python Chess

spike111 wrote:

make a line of code that deletes the printed pawn on e3

it's solved -.-


http://gigabyte.50webs.com/funnyerrormessages/work013.jpg

Offline

 

Board footer