F
F
frankwolf2018-06-30 12:23:17
Python
frankwolf, 2018-06-30 12:23:17

How to solve AttributeError 'list' object has no attribute 'empty'?

Hello, help me solve the problem. I am learning to program
File "D:\Desktop\checkers\field.py", line 61, in empty_pos
self.checkerboard[int(position[1]) - 1]['field'][position[0]][1 ] = False
AttributeError: 'list' object has no attribute 'checkerboard'

class Field:
    empty = False
    fill = True
    black = True
    white = False
    team = None
    checker = None

    s8 = {'number': '8', 'field': {'A': [white, empty, checker, team],'B': [black, empty, checker, team], 
    'C': [white, empty, checker, team], 'D': [black, empty, checker, team],
    'E': [white, empty, checker, team], 'F': [black, empty, checker, team], 
    'G': [white, empty, checker, team], 'H': [black, empty, checker, team]}}
    s7 = {'number': '7', 'field': {'A': [black, empty, checker, team],'B': [white, empty, checker, team],
    'C': [black, empty, checker, team], 'D': [white, empty, checker, team], 
    'E': [black, empty, checker, team], 'F': [white, empty, checker, team],
    'G': [black, empty, checker, team], 'H': [white, empty, checker, team]}}
    s6 = {'number': '6', 'field': {'A': [white, empty, checker, team],'B': [black, empty, checker, team],
    'C': [white, empty, checker, team], 'D': [black, empty, checker, team], 
    'E': [white, empty, checker, team], 'F': [black, empty, checker, team],
    'G': [white, empty, checker, team], 'H': [black, empty, checker, team]}}
    s5 = {'number': '5', 'field': {'A': [black, empty, checker, team],'B': [white, empty, checker, team],
    'C': [black, empty, checker, team], 'D': [white, empty, checker, team],
    'E': [black, empty, checker, team], 'F': [white, empty, checker, team],
    'G': [black, empty, checker, team], 'H': [white, empty, checker, team]}}
    s4 = {'number': '4', 'field': {'A': [white, empty, checker, team],'B': [black, empty, checker, team],
    'C': [white, empty, checker, team], 'D': [black, empty, checker, team], 
    'E': [white, empty, checker, team], 'F': [black, empty, checker, team], 
    'G': [white, empty, checker, team], 'H': [black, empty, checker, team]}}
    s3 = {'number': '3', 'field': {'A': [black, empty, checker, team],'B': [white, empty, checker, team],
    'C': [black, empty, checker, team], 'D': [white, empty, checker, team],
    'E': [black, empty, checker, team], 'F': [white, empty, checker, team],
    'G': [black, empty, checker, team], 'H': [white, empty, checker, team]}}
    s2 = {'number': '2', 'field': {'A': [white, empty, checker, team],'B': [black, empty, checker, team],
    'C': [white, empty, checker, team], 'D': [black, empty, checker, team],
    'E': [white, empty, checker, team], 'F': [black, empty, checker, team], 
    'G': [white, empty, checker, team], 'H': [black, empty, checker, team]}}
    s1 = {'number': '1', 'field': {'A': [black, empty, checker, team],'B': [white, empty, checker, team],
    'C': [black, empty, checker, team], 'D': [white, empty, checker, team],
    'E': [black, empty, checker, team], 'F': [white, empty, checker, team],
    'G': [black, empty, checker, team], 'H': [white, empty, checker, team]}}
    checkerboard = [s1, s2, s3, s4, s5, s6, s7, s8]
    __keys_position = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
    __numbers_position = [1, 2, 3, 4, 5, 6, 7, 8]
    #Example for Position: ['A'; '2']

    def match(line, column, param, self):
        self.checkerboard[int(line) - 1][str(line)][column] = param 
        return True

    def setPosition(line, column, param, self):
        self.checkerboard[int(line) - 1][str(line)][column][1] = param
        return True

    def fill_pos(position, checker, team, self):
        self.checkerboard[int(position[1]) - 1]['field'][position[0]][1] = self.fill
        self.checkerboard[int(position[1]) - 1]['field'][position[0]][2] = checker
        self.checkerboard[int(position[1]) - 1]['field'][position[0]][3] = team
        return True

    def empty_pos(position, self):
        self.checkerboard[int(position[1]) - 1]['field'][position[0]][1] = self.empty
        self.checkerboard[int(position[1]) - 1]['field'][position[0]][2] = self.checker
        self.checkerboard[int(position[1]) - 1]['field'][position[0]][3] = self.team
        return True

    def setDefaultPosition(self):
        i = 0
        for a in self.checkerboard:
            if int(a['number']) % 2 == 0 and int(a['number']) != 5 and int(a['number']) != 4:
                self.checkerboard[i]['field']['B'][1] = self.fill;self.checkerboard[i]['field']['B'][2] = False
                self.checkerboard[i]['field']['D'][1] = self.fill;self.checkerboard[i]['field']['D'][2] = False
                self.checkerboard[i]['field']['F'][1] = self.fill;self.checkerboard[i]['field']['F'][2] = False
                self.checkerboard[i]['field']['H'][1] = self.fill;self.checkerboard[i]['field']['H'][2] = False
            if int(a['number']) % 2 != 0 and int(a['number']) != 5 and int(a['number']) != 4:
                self.checkerboard[i]['field']['A'][1] = self.fill;self.checkerboard[i]['field']['A'][2] = False 
                self.checkerboard[i]['field']['C'][1] = self.fill;self.checkerboard[i]['field']['C'][2] = False 
                self.checkerboard[i]['field']['E'][1] = self.fill;self.checkerboard[i]['field']['E'][2] = False
                self.checkerboard[i]['field']['G'][1] = self.fill;self.checkerboard[i]['field']['G'][2] = False
            i += 1
        i = 0
        for el in self.checkerboard:
        	if int(el['number']) >= 6:
        		for e in self.checkerboard[i]['field']:
        			for m in self.checkerboard[i]['field'][e]:
        				if self.checkerboard[i]['field'][e][0] != self.white:
        					self.checkerboard[i]['field'][e][3] = 1
        	if int(el['number']) <= 3:
        		for e in self.checkerboard[i]['field']:
        			for m in self.checkerboard[i]['field'][e]:
        				if self.checkerboard[i]['field'][e][0] != self.white:
        					self.checkerboard[i]['field'][e][3] = 2
        	i += 1

    def reset(self):
    	pass



    def isFill(position, self):
        if self.checkerboard[int(position[1]) - 1]['field'][position[0]][1] == self.fill:
            return True
        else:
            return False

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question