PYTHON   18

TestHarness.py

Guest on 6th June 2021 05:09:44 PM

  1. #   TestHarness.py -- Game of Life test harness
  2.  
  3. from GameBoard4 import Board
  4. from LifeDisplay4 import SetUpLifeDisplay, Stopped
  5. import time
  6.  
  7.  
  8. def getInputFile():
  9.     fileName = input("Enter file name to initialize:- ")
  10.     inputFile = open(fileName, 'r')
  11.     lines = inputFile.readlines()
  12.     numberOfLines = len(lines)
  13.  
  14.     for i in range(numberOfLines):
  15.         #   Strip trailing newline character
  16.         lines[i] = lines[i][:-1]
  17.     return lines
  18.  
  19. def main():
  20.     print("Welcome to the Game of Life.")
  21.  
  22.     #   Create game window
  23.     initStrings = getInputFile()
  24.  
  25.     SetUpLifeDisplay(150, 100)
  26.  
  27.     board = Board(initStrings)
  28.  
  29. ##    for x in range(-1, 2):
  30. ##        for y in range (-1, 2):
  31. ##            n = currBoard.countNeighbors(x, y)
  32. ##            print("Element ", x, ",", y, " has ", n,
  33. ##                  " neighbors\n", sep='')
  34.  
  35. ##    c = 0
  36. ##    for organism in currBoard.enumerateOrganisms():
  37. ##        row, col = organism.getCoords()
  38. ##        print("Element", c, "is row", row, ", column", col)
  39. ##        print("  The neighboring spaces are [", end='')
  40. ##        for (nRow, nCol) in currBoard.enumerateNeighbors(row, col):
  41. ##            print("(", nRow, ", ", nCol, "), ", sep = '', end='')
  42. ##        print("]\n")
  43. ##        c += 1
  44.     #print("The initial board is:-")
  45.     #board.printBoard()
  46.  
  47.     i = 0
  48.     while i < 1200:
  49.         time.sleep(0.25)
  50.         prevBoard = board
  51.         board = Board(prevBoard)
  52.         if board.maxRow() <= board.minRow() and \
  53.            board.maxCol() <= board.minCol():
  54.             print("Empty board!")
  55.             break
  56.         elif Stopped():
  57.             print("Stop button pressed.")
  58.             break
  59.         #print("Board[", i, "] is:-", sep='')
  60.         #board.printBoard()
  61.         i += 1
  62.  
  63.     return
  64.  
  65.    
  66.     return
  67.  
  68. if __name__ == '__main__':
  69.     main()

Raw Paste


Login or Register to edit or fork this paste. It's free.