<commit_before>### Implementation of the Lightsweeper floor
from LSRealTile import LSRealTile
from LSRealTile import lsOpen

import time
import os
import random
import Colors
import Shapes
import json
from collections import defaultdict
from Move import Move
from LSAudio import Audio

OURWAIT = 0.005

#handles all communications with RealTile objects, serving as the interface to the
#actual lightsweeper floor. thus updates are pushed to it (display) and also pulled from it
#(sensor changes)
class LSRealFloor():
    COLS = 8
    ROWS = 6
    SENSOR_THRESHOLD = 230
    sharedSerials = list()

    def __init__(self, rows=ROWS, cols=COLS, serials=None):
        fileName = 'Bfloor' # Testing
        self.rows = rows
        self.cols = cols
        print("RealFloor init", rows, cols)

        tilepile = lsOpen()

        for port in tilepile.lsMatrix:
            self.sharedSerials.append(port)
        print(repr(self.sharedSerials))  #debugging
        
  # Old code:
#        if serials is None:
#            # top-left, A1,2,3
#            comPort1 = "COM5"
#            # top-right, A4,5,6
#            comPort2 = "COM12"
#            # bottom-left, B1,2,3
#            comPort3 = "COM13"
#            # bottom-right, B4,5,6
#            comPort4 = "COM15"
#            availPorts = list(serial_ports())
#            print("Available serial ports:" + str(availPorts))
#            print("connecting to ", comPort1, comPort2, comPort3, comPort4)
#            serial1 = None
#            serial2 = None
#            serial3 = None
#            serial4 = None
#            try:
#                serial1 = Serial(comPort1, 19200, timeout=0.005)
#            except IOError:
#                print("Could not open", comPort1)
#            try:
#                serial2 = Serial(comPort2, 19200, timeout=0.005)
#            except IOError:
#               print("Could not open", comPort2)
#            try:
#                serial3 = Serial(comPort3, 19200, timeout=0.005)
#            except IOError:
#                print("Could not open", comPort3)
#            try:
#                serial4 = Serial(comPort4, 19200, timeout=0.005)
#            except IOError:
#                print("Could not open", comPort4)
#            self.sharedSerials = [serial1, serial2, serial3, serial4]
#            print("finished with COM ports")
#        else:
#            self.sharedSerials = serials

        self.addressToRowColumn = {}
        # make all the rows
        self.tileRows = []
        conf = lsConfig(fileName)
        print("Loaded " + str(conf.rows) + " rows and " + str(conf.cols) + " columns (" + str(conf.cells) + " tiles)")
        
        for row in conf.board:
            for j in range(cols):
                self.tileRows[i].append(None)
            for col in conf.board[row]:
                (port, address) = conf.board[row][col]
                tile = LSRealTile(tilepile.lsSerial(port))
                tile.comNumber = port

            tile.assignAddress(address)
                self.addressToRowColumn[(address,port)] = (row, col)
            col = int(line[1])
            tile.setColor(Colors.WHITE)
            tile.setShape(Shapes.ZERO)
                print("address assigned:", tile.getAddress())
            s = ""
                wait(.1)
                tile = self.tileRows[i][j]

        
        
 # Old code:        
#        for row in range(rows):
#            tiles = []
#            self.tileAddresses = []
#            for col in range(cols):
#                line = ""
#                while line is "":
#                    line = (pickle.readline()).strip('()\n').replace('\'','')
#                line = tuple(line.split(','))
#                # the COM entry should just be the number 1, 2, 3, or 4 instead of the COM port.
#                # 1 being top-left, 4 bottom-right
#                comNumber = int(line[2]) - 1
#                tile = LSRealTile(self.sharedSerials[comNumber])
#                tile.comNumber = comNumber<commit_msg>Deprecated old tile-address assignment routine<commit_after>### Implementation of the Lightsweeper floor
from LSRealTile import LSRealTile
from LSRealTile import lsOpen

import time
import os
import random
import Colors
import Shapes
import json
from collections import defaultdict
from Move import Move
from LSAudio import Audio

OURWAIT = 0.005

#handles all communications with RealTile objects, serving as the interface to the
#actual lightsweeper floor. thus updates are pushed to it (display) and also pulled from it
#(sensor changes)
class LSRealFloor():
    COLS = 8
    ROWS = 6
    SENSOR_THRESHOLD = 230
    sharedSerials = list()

    def __init__(self, rows=ROWS, cols=COLS, serials=None):
        fileName = 'Bfloor' # Testing
        self.rows = rows
        self.cols = cols
        print("RealFloor init", rows, cols)

        tilepile = lsOpen()

        for port in tilepile.lsMatrix:
            self.sharedSerials.append(port)
        print(repr(self.sharedSerials))  #debugging
        
  # Old code:
#        if serials is None:
#            # top-left, A1,2,3
#            comPort1 = "COM5"
#            # top-right, A4,5,6
#            comPort2 = "COM12"
#            # bottom-left, B1,2,3
#            comPort3 = "COM13"
#            # bottom-right, B4,5,6
#            comPort4 = "COM15"
#            availPorts = list(serial_ports())
#            print("Available serial ports:" + str(availPorts))
#            print("connecting to ", comPort1, comPort2, comPort3, comPort4)
#            serial1 = None
#            serial2 = None
#            serial3 = None
#            serial4 = None
#            try:
#                serial1 = Serial(comPort1, 19200, timeout=0.005)
#            except IOError:
#                print("Could not open", comPort1)
#            try:
#                serial2 = Serial(comPort2, 19200, timeout=0.005)
#            except IOError:
#               print("Could not open", comPort2)
#            try:
#                serial3 = Serial(comPort3, 19200, timeout=0.005)
#            except IOError:
#                print("Could not open", comPort3)
#            try:
#                serial4 = Serial(comPort4, 19200, timeout=0.005)
#            except IOError:
#                print("Could not open", comPort4)
#            self.sharedSerials = [serial1, serial2, serial3, serial4]
#            print("finished with COM ports")
#        else:
#            self.sharedSerials = serials

        self.addressToRowColumn = {}
        # make all the rows
        self.tileRows = []
        conf = lsConfig(fileName)
        print("Loaded " + str(conf.rows) + " rows and " + str(conf.cols) + " columns (" + str(conf.cells) + " tiles)")
        
        
        for row in conf.board:
            tiles = []
            self.tileAddresses = []
            for col in conf.board[row]:
                (port, address) = conf.board[row][col]
                tile = LSRealTile(tilepile.lsSerial(port))
                tile.comNumber = port

                tile.assignAddress(address)
                self.addressToRowColumn[(address,port)] = (row, col)
                tile.setColor(Colors.WHITE)
                tile.setShape(Shapes.ZERO)
                print("address assigned:", tile.getAddress())
                tiles.append(tile)
                wait(.1)
            self.tileRows.append(tiles)
        
        
        
        # Deprecated
        #for row in conf.board:
            #for j in range(cols):
            #    self.tileRows[j].append(None)
            #for col in conf.board[row]:
            #    (port, address) = conf.board[row][col]
            #    tile = LSRealTile(tilepile.lsSerial(port))
            #    tile.comNumber = port

         #   tile.assignAddress(address)
         #   self.addressToRowColumn[(address,port)] = (row, col)
         #   col = int(line[1])
         #   tile.setColor(Colors.WHITE)
         #   tile.setShape(Shapes.ZERO)
         #   print("address assigned:", tile.getAddress())
         #   s = ""
         #   wait(.1)
         #   tile = self.tileRows[i][j]

        
        
 # Old code:        
#        for row in range(rows):
#            tiles = []
#            self.tileAddresses = []
#            for col in range(cols):
#                line = ""
#                while line is "":
#                    line = (pickle.readline()).strip('()\n').replace('\'','')
#                line = tuple(line.split(','))
#                # the COM entry should just be the number 1, 2, 3, or 4 instead of the COM port.
#                # 1 being top-left, 4 bottom-right
#                comNumber = int(line[2]) - 1
#                tile = LSRealTile(self.sharedSerials[comNumber])
#                tile.comNumber = comNumber
{'fraction_non_alphanumeric': 0.11031010413090743, 'fraction_numerical': 0.023458061563107906, 'mean_word_length': 1.675237220691766, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2794319', 'n_tokens_mistral': 2688, 'n_tokens_neox': 2516, 'n_words': 639}