1

I was reading a code of 2048 game and came across the following snippet

def up(game):
    print("up")
    # return matrix after shifting up
    game=transpose(game)
    game,done=cover_up(game)
    temp=merge(game)
    game=temp[0]
    done=done or temp[1]
    game=cover_up(game)[0]
    game=transpose(game)
    return (game,done)

according to my understanding, game is a matrix that is passed to a function that executes multiple function to preform up logic on the game. I am not able to understand the line

game,done=cover_up(game)

done is a boolean variable.

My other doubt is

done=done or temp[1]

Temp is a temporary variable for the matrix. boolean = True/false OR Matrix this doesn't make sense to me. Please help me with the following syntax I am new to python. Thank you

Sagar Moghe
  • 67
  • 1
  • 7
  • 1
    For the second, `done` will evaluate to `temp[0]` if it's falsey originally. If you pay around with `or`, you'll learn some interesting tricks like that. And what part about the first are you having issues with? – Carcigenicate Feb 12 '18 at 03:57
  • 1
    The issue here is not the python syntax, which is not hard to follow. The code snippet you have shown is IMHO an example of how not to write self explaining code : 1. Short and non informative method names 2. Magic numbers 3. Unclear usage of a temporary array – Rann Lifshitz Feb 12 '18 at 04:01

0 Answers0