Muchos de ustedes siguen el tutorial de QBasic que voy haciendo y se preguntan ¿Que puedo hacer con este lenguaje que en el fondo no tiene casi poder comparado con los monstruos como C o Java? Pués bien, el lenguaje lo estamos usando para aprender a programar, pero eso no quita que se puedan hacer cosas interesantes con el.
Por ejemplo, me puse como objetivo programar una versión QB64 del Juego de la vida que sea lo más parametrizable posible. Les dejo aquí una primer versión que iré mejorando a través de los videos que voy a ir presentando:
Les dejo el código de esta primer versión, que es MUY mejorable:
REM GAME LIFE
REM RULES:
REM 1-Any live cell with fewer than two live neighbours dies, as if caused by under-population.
REM 2-Any live cell with two or three live neighbours lives on to the next generation.
REM 3-Any live cell with more than three live neighbours dies, as if by overcrowding.
REM 4-Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
SCREEN 12
INPUT "Enter dimentions of the board:", dimension
DIM board(0 TO dimension + 1, 0 TO dimension + 1)
DIM nextboard(0 TO dimension + 1, 0 TO dimension + 1)
INPUT "Enter turns: ", turns
REM --------SET BOARD--------
FOR i = 0 TO dimension + 1
board(i, 0) = 0
board(0, i) = 0
board(i, dimension + 1) = 0
board(dimension + 1, i) = 0
nextboard(i, 0) = 0
nextboard(0, i) = 0
nextboard(i, dimension + 1) = 0
nextboard(dimension + 1, i) = 0
NEXT
RANDOMIZE TIMER
FOR i = 1 TO dimension
FOR j = 1 TO dimension
board(i, j) = INT(RND * 2)
NEXT
NEXT
REM ----------DRAW BOARD------------
CALL drawBoard(dimension, board())
actualTurn = 1
DO WHILE turns > actualTurn
SLEEP 1
FOR i = 1 TO dimension
FOR j = 1 TO dimension
cant = returnAliveNeighbours(board(), i, j, dimension)
IF board(i, j) = 1 THEN
IF cant < 2 OR cant > 3 THEN
nextboard(i, j) = 0
END IF
END IF
IF board(i, j) = 0 THEN
IF cant = 3 THEN
nextboard(i, j) = 1
END IF
END IF
NEXT
NEXT
FOR i = 1 TO dimension
FOR j = 1 TO dimension
board(i, j) = nextboard(i, j)
NEXT
NEXT
CALL drawBoard(dimension, board())
actualTurn = actualTurn + 1
LOOP
SUB drawBoard (dimension, board())
FOR i = 1 TO dimension
FOR j = 1 TO dimension
IF board(i, j) = 0 THEN
LINE ((i - 1) * (640 / dimension), (j - 1) * (480 / dimension))-((i - 1) * (640 / dimension) + (640 / dimension), (j - 1) * (480 / dimension) + (480 / dimension)), 0, BF
ELSE
LINE ((i - 1) * (640 / dimension), (j - 1) * (480 / dimension))-((i - 1) * (640 / dimension) + (640 / dimension), (j - 1) * (480 / dimension) + (480 / dimension)), 6, BF
END IF
NEXT
NEXT
FOR i = 1 TO dimension
LINE (0, i * (480 / dimension))-(640, i * (480 / dimension)), 4
LINE (i * (640 / dimension), 0)-(i * (640 / dimension), 480), 4
NEXT
END SUB
FUNCTION returnAliveNeighbours (board(), px, py, dimension)
aliveNeighbours = 0
aliveNeighbours = board(px - 1, py - 1) + board(px, py - 1) + board(px + 1, py - 1) + board(px - 1, py) + board(px + 1, py) + board(px - 1, py + 1) + board(px, py + 1) + board(px + 1, py + 1)
returnAliveNeighbours = aliveNeighbours
END FUNCTIONEspero sus críticas, comentarios, maneras en la que harían este programa, etc.
P.D.: Entiendo que está en inglés, pero bueno, ya que estaba practicaba un poco.



