Python Forum
snakes and ladders board creation help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
snakes and ladders board creation help
#2
Two ways to do this come to mind. You can store the board as a list of lists, or you can build the board as you display it. Here's a couple examples on a 5 x 5 board:

board = [['.'] * 5 for row in range(5)]
board[1][2] = '1' # player 1 position
board[3][4] = '2' # player 2 position
print('\n'.join([''.join(row) for row in board]))
Or building as you go along:

text = ''
for row in range(5):
    for column in range(5):
        if row * 5 + column == player1position:
            text += '1'
        elif row * 5 + column == player2position:
            text += '2'
        else:
            text += '.'
    text += '\n'
I'm using a calculation in the building version, but you can do sort of the reverse calculation in the list of lists: board[player1position // 5][player1position % 5].

Keep in mind that if you are using the list version, you have to remove the old positions when you put the players in a new position.

Note that both of these will have the player move down the board, visually. If you want them to move up the board, you would have to reverse the rows in the list when printing them, or run the row loop from 4 to 0 when building the board.

This is not the limit of the ways you can build a board, but just some quick ideas.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: snakes and ladders board creation help - by ichabod801 - Aug-25-2017, 01:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to make a board with turtle, nothing happens when running script Quascia 3 677 Nov-01-2023, 03:11 PM
Last Post: deanhystad
Photo HOW FIX MY BOARD GAME LAZABI 3 1,476 Apr-01-2022, 04:23 PM
Last Post: BashBedlam
  The game should now run and terminate once the board is full, but still can’t identif rango 0 1,460 Jul-22-2021, 03:24 AM
Last Post: rango
  Enabling interrupt on Adafruits button/led board Moris526 0 2,025 Apr-30-2021, 03:29 PM
Last Post: Moris526
  High-Precision Board Voltage Reading from Python into PD Liam484 1 2,087 Mar-29-2021, 02:57 PM
Last Post: Marbelous
  Interrupt for Adafruits Neotrellis button/led board Moris526 0 1,806 Dec-28-2020, 05:42 AM
Last Post: Moris526
  [Help] A function that generates an n x n sized board? vanicci 5 4,768 Aug-14-2018, 02:26 PM
Last Post: vanicci
  Serial communication with a board Bokka 2 5,361 Dec-07-2017, 07:34 AM
Last Post: Bokka
  Communicating C++ and Python in Jetson TK1 board. hlfan1234567 1 3,188 Jul-09-2017, 04:22 PM
Last Post: hlfan1234567

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020