# thanks chat-gpt for the help...

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout

tagged_set = {
"STONE2"  : 3,
"STONE3"  : 3,
"SW1BRIK" : 3,
"SW2BRIK" : 3,
"SW1STON1": 3,
"SW2STON1": 3,
"CEMENT1" : 3,
"CEMENT2" : 3,
"CEMENT3" : 3,
"CEMENT4" : 3,
"CEMENT5" : 3,
"CEMENT6" : 3,
"SW1CMT"  : 3,
"SW2CMT"  : 3,
"BLODRIP1": 0,
"BLODRIP2": 0,
"BLODRIP3": 0,
"BLODRIP4": 0,
"DOORBLU2": 0,
"DOORRED2": 0,
"DOORYEL2": 0,
"FIREBLU1": 0,
"FIREBLU2": 0,
"FIRELAV2": 0,
"FIRELAV3": 0,
"FIRELAVA": 0,
"FIREMAG1": 0,
"FIREMAG2": 0,
"FIREMAG3": 0,
"FIREWALA": 0,
"FIREWALB": 0,
"FIREWALL": 0,
"PIPE1": 0,
"REDWALL": 0,
"SK_LEFT": 0,
"SK_RIGHT": 0,
"SKIN2": 0,
"SKINCUT": 0,
"SKINEDGE": 0,
"SKINFACE": 0,
"SKINLOW": 0,
"SKINMET1": 0,
"SKINMET2": 0,
"SKINSCAB": 0,
"SKINSYMB": 0,
"SKSNAKE1": 0,
"SKSNAKE2": 0,
"SKSPINE1": 0,
"SKSPINE2": 0,
"SLOPPY1": 0,
"SLOPPY2": 0,
"SP_FACE1": 0,
"SP_FACE2": 0,
"SP_HOT1": 0,
"SW1HOT": 0,
"SW2HOT": 0,
"SW1SKIN": 0,
"SW2SKIN": 0,
"GSTFONT1": 0,
"GSTFONT2": 0,
"GSTFONT3": 0,
"GSTGARG": 0,
"GSTLION": 0,
"GSTONE1": 0,
"GSTONE2": 0,
"GSTSATYR": 0,
"GSTVINE1": 0,
"GSTVINE2": 0,
"MARBFAC2": 0,
"MARBFAC3": 0,
"MARBFACE": 0,
"MARBLE1": 0,
"MARBLE2": 0,
"MARBLE3": 0,
"MARBLOD1": 0,
"SP_DUDE1": 0,
"SP_DUDE2": 0,
"SP_DUDE4": 0,
"SP_DUDE5": 0,
"SW1GSTON": 0,
"SW2GSTON": 0,
"SW1MARB": 0,
"SW2MARB": 0,
"BIGDOOR2": 2,
"BIGDOOR3": 2,
"BIGDOOR4": 2,
"BRNPOIS": 2,
"BRNSMAL1": 2,
"BRNSMAL2": 2,
"BRNSMALC": 2,
"BRNSMALL": 2,
"BRNSMALR": 2,
"BROVINE2": 2,
"BROWN1": 2,
"BROWN144": 2,
"BROWN96": 2,
"BROWNGRN": 2,
"BROWNHUG": 2,
"BROWNPIP": 2,
"CRATE1": 2,
"CRATE2": 2,
"CRATELIT": 2,
"CRATINY": 2,
"CRATWIDE": 2,
"DOORBLU": 2,
"DOORRED": 2,
"DOORSTOP": 2,
"DOORTRAK": 2,
"DOORYEL": 2,
"EXITDOOR": 2,
"EXITSIGN": 2,
"EXITSTON": 2,
"GRAY1": 2,
"GRAY2": 2,
"GRAY4": 2,
"GRAY5": 2,
"GRAY7": 2,
"GRAYBIG": 2,
"GRAYPOIS": 2,
"GRAYTALL": 2,
"GRAYVINE": 2,
"ICKWALL1": 2,
"ICKWALL2": 2,
"ICKWALL3": 2,
"ICKWALL4": 2,
"ICKWALL5": 2,
"ICKWALL7": 2,
"NUKE24": 2,
"NUKEDGE1": 2,
"NUKEPOIS": 2,
"PIPE2": 2,
"PIPE4": 2,
"PIPE6": 2,
"PLAT1": 2,
"SLADPOIS": 2,
"SLADSKUL": 2,
"SLADWALL": 2,
"STEP2": 2,
"STEP3": 2,
"STEP4": 2,
"STEPTOP": 2,
"SUPPORT3": 2,
"SW1BRCOM": 2,
"SW2BRCOM": 2,
"SW1BRN1": 2,
"SW2BRN1": 2,
"SW1BRN2": 2,
"SW2BRN2": 2,
"SW1BRNGN": 2,
"SW2BRNGN": 2,
"SW1BROWN": 2,
"SW2BROWN": 2,
"SW1DIRT": 2,
"SW2DIRT": 2,
"SW1EXIT": 2,
"SW2EXIT": 2,
"SW1GRAY": 2,
"SW2GRAY": 2,
"SW1GRAY1": 2,
"SW2GRAY1": 2,
"SW1PIPE": 2,
"SW2PIPE": 2,
"SW1SLAD": 2,
"SW2SLAD": 2,
"SW1STARG": 2,
"SW2STARG": 2,
"SW1STON2": 2,
"SW2STON2": 2,
"SW1STONE": 2,
"SW2STONE": 2,
"SW1VINE": 2,
"SW2VINE": 2,
"METAL": 2,
"METAL1": 2,
"MIDBRN1": 2,
"MIDGRATE": 2,
"SW1GARG": 2,
"SW2GARG": 2,
"SW1LION": 2,
"SW2LION": 2,
"SW1MET2": 2,
"SW2MET2": 2,
"SW1METAL": 2,
"SW2METAL": 2,
"SW1SATYR": 2,
"SW2SATYR": 2,
"ROCKRED1": 1,
"ROCKRED2": 1,
"ROCKRED3": 1,
"SP_ROCK1": 1,
"STONE": 1,
"SW1STON6": 1,
"SW2STON6": 1,
"BIGDOOR1": 2,
"BLAKWAL1": 2,
"BLAKWAL2": 2,
"COMPBLUE": 2,
"COMPSPAN": 2,
"COMPSTA1": 2,
"COMPSTA2": 2,
"COMPTALL": 2,
"COMPWERD": 2,
"DOOR1": 2,
"DOOR3": 2,
"LITE3": 2,
"LITE5": 2,
"LITEBLU1": 2,
"LITEBLU4": 2,
"SHAWN1": 2,
"SHAWN2": 2,
"SHAWN3": 2,
"STARBR2": 2,
"STARG1": 2,
"STARG2": 2,
"STARG3": 2,
"STARGR1": 2,
"STARGR2": 2,
"STARTAN2": 2,
"STARTAN3": 2,
"STEP1": 2,
"STEP5": 2,
"STEP6": 2,
"STEPLAD1": 2,
"SUPPORT2": 2,
"SW1BLUE": 2,
"SW2BLUE": 2,
"SW1COMM": 2,
"SW2COMM": 2,
"SW1COMP": 2,
"SW2COMP": 2,
"SW1MOD1": 2,
"SW2MOD1": 2,
"SW1STRTN": 2,
"SW2STRTN": 2,
"TEKWALL1": 2,
"TEKWALL4": 2,
"BIGDOOR5": 3,
"BIGDOOR6": 3,
"BIGDOOR7": 3,
"SW1WOOD":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OOR7_1": 2,
"FLOOR7_2": 0,
"F_SKY1": 1,
"FWATER1": 1,
"FWATER2": 1,
"FWATER3": 1,
"FWATER4": 1,
"GATE1": 2,
"GATE2": 2,
"GATE3": 2,
"GATE4": 2,
"LAVA1": 0,
"LAVA2": 0,
"LAVA3": 0,
"LAVA4": 0,
"MFLR8_1": 3,
"MFLR8_2": 1,
"MFLR8_3": 1,
"MFLR8_4": 1,
"NUKAGE1": 2,
"NUKAGE2": 2,
"NUKAGE3": 2,
"SFLR6_1": 0,
"SFLR6_4": 0,
"SFLR7_1": 0,
"SFLR7_4": 0,
"STEP1": 2,
"STEP2": 2,
"TLITE6_1": 2,
"TLITE6_4": 2,
"TLITE6_5": 2,
"TLITE6_6": 2,
}

model = Sequential()

# Convolutional layers
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(256, 128, 3)))
model.add(MaxPooling2D((2, 2)))

model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D((2, 2)))

model.add(Conv2D(128, (3, 3), activation='relu'))
model.add(MaxPooling2D((2, 2)))

# Flatten layer
model.add(Flatten())

# Fully connected layers
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))

num_categories = 4

# Output layer
model.add(Dense(num_categories, activation='softmax'))

# Compile the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# Train the model
model.fit(x_train, y_train, epochs=20, batch_size=64, validation_data=(x_val, y_val))