stardance has been extended another month! the new deadline is october 31 :)

You are browsing as a guest. Sign up (or log in) to start making projects!

1h 3m 17s logged

Devlog 2

Did not do much for this devlog. I mainly did refactor work and cleaning up my code. But I discovered a new thing about python.

DUNDER METHODS

These are actually really cool and they add some additional functionality to your classes that you make. For example in my use I use the:

__str__()

dunder (double underscore) method which allows me to call print() on my class and print whatever I want to print for my class. Here is how I’m using it:

# inside of the board class
def __str__(self):
     board_str = ""
     for y in range(8):
        for x in range(8):
             piece = self.grid[x][y]
             if piece:
                  board_str += f"{piece.type[0].upper() if piece.team == 'white' else piece.type[0].lower()} "
             else:
                 board_str += ". "
            board_str += "\n"
     return board_str

# How you call it assuming you've already declared a board object called board.
print(board) 

This allows for easier and cleaner code for debugging. This code snippet prints what is shown in the photo.

0
49

Comments 2

@yoonha

That looks like a great start! I suggest you change the knights’ character from K to N because it might be confused for the king and the official notation for knights is N

@caleb_welch

@yoonha Great idea