Python Forum
movement in a zigzag in a 2d array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
movement in a zigzag in a 2d array
#1
I need to move in a zigzag (like snakes and ladders) from the start to the end of the grid.
Here's my code so far:

import random
def cls():
    print("\n" * 100)
    # clears screen

def create_grid():
    # create a 2d array with the specified dimensions & contents called 3 times to create the 3 game tables
    grid = []
    for x in range(7):
        grid.append([])
        for y in range(7):
            grid[x].append("  ")

    for i in range(7):
        a = i + 1
        b = 14 - i
        c = 15 + i
        d = 28 - i
        e = 29 + i
        f = 42 - i
        g = 43 + i
        string1 = str(a)
        string2 = "0" + string1
        grid[6][i] = string2
        grid[5][i] = str(b)
        grid[5][6] = "08"
        grid[5][5] = "09"
        grid[4][i] = str(c)
        grid[3][i] = str(d)
        grid[2][i] = str(e)
        grid[1][i] = str(f)
        grid[0][i] = str(g)
    return grid
print(create_grid())
def roll_dice():
    roll_one = random.randint(1, 6)
    roll_two = random.randint(1, 6)
    return roll_one, roll_two

def move_counter():
    move = 0
    return move

def starter_position():
    p1_x_current = 0
    p1_y_current = 6
    p1_x_previous = 0
    p1_y_previous = 6
    p2_x_current = 0
    p2_y_current = 6
    p2_x_previous = 0
    p2_y_previous = 6
    return p1_x_current, p1_y_current, p1_x_previous, p1_y_previous, p2_x_current, p2_y_current, p2_x_previous, p2_y_previous

def movement(move, p1_x_current, p1_y_current, p1_x_previous, p1_y_previous, p2_x_current, p2_y_current, p2_x_previous, p2_y_previous):
    dice_roll = roll_dice()
    move

    position

def print_grid(grid):
    print("-" * (7 * 4))
    for y in range(0, 7):
        print("|" + "|".join(grid[y]) + "|")
        print("-" * (7 * 4))
        grid[6][0] = ' p'
print(print_grid(create_grid()))
Reply
#2
dir = 1
for row in list_of_rows:
    for column in row[::dir]:
        ....
    dir *= -1
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to make the movement humanized isv 4 1,502 Jul-29-2022, 07:14 PM
Last Post: XavierPlatinum
  How to get continuous movement whilst using State Machine cjoe1993 2 1,787 Dec-10-2020, 06:36 AM
Last Post: cjoe1993
  An important question is how to create a zigzag in price data? epsilon 0 1,271 Nov-18-2020, 08:06 PM
Last Post: epsilon
  zigzag example shabux 10 5,263 Jul-11-2020, 11:15 PM
Last Post: bowlofred
  Moving mouse so that games can detect movement SheeppOSU 2 1,898 Jun-09-2020, 07:23 PM
Last Post: SheeppOSU
  need help on solving and movement Tankey2630 1 1,651 Jan-09-2020, 11:04 AM
Last Post: Tankey2630
  Count to movement according to the time pressed button noartist 1 2,472 Feb-27-2019, 01:33 PM
Last Post: noartist
  Can't change Right to left id spawning/ movement to top to bottom Kingrocket10 3 3,761 Dec-14-2017, 11:05 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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