-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_decorum_solver.py
More file actions
802 lines (685 loc) · 41.6 KB
/
simple_decorum_solver.py
File metadata and controls
802 lines (685 loc) · 41.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
# This file is dedicated to efficiently finding ONE SOLUTION to a given set of decorum requirements.
# To this end, I need to be able to define constraints, and then whittle down the solution space as much as possible as quickly as possible.
# So, How the hell do I do that?
## I need to prune early. Generating all solutions for up to 7 or 8 objects is doable (1-10 seconds), but 12 is impossible (>80,000 seconds)
## So I need to prune, but I need a way to prune efficiently, which is unfortunately based strongly on how I order my variables.
## HEURISTICS
# MRV, choose next variable in assignment based on minimum number of domains for each variable
### THIS IS FAST, so it should happen often
## This requires defining how the domains change based on constraints whenever I set a new value.
# FORCE, choose next variable based on **shortest span** ordering for variables.
### THIS ONLY CHANGES IF I USE MRV!!! So every time MRV changes the order of things, rerun this?
## This requires a mapping of constraints and variables.
## NOTE: Shortest span is a choice. I could use a different heuristic for shortening
# Connectivity, choose next variable based on how many constraints this variable is used in.
### THIS doesn't change.
# MRV IMPLEMENTED
# FORCE NOT IMPLEMENTED
# CONNECTIVITY NOT IMPLEMENTED
# Use all of these, maybe with a weighting system, if the domain only has one option (found through MRV), this must take precedence. Otherwise, MRV and FORCE seem most important, and connectivity after them.
import pprint
from constraint_definitions import *
import time
import random
wall_colors = {1, 2, 3, 4} # red, yellow, green, blue
object_colors = {0, 1, 2, 3, 4} # Empty, red, yellow, green, blue. [Yes, objects have styles too, but I'm only testing generation time rn]
puzzle = [-1]*16 # -1 here means "unassigned"
# possible_houses = []
MAX_SOLUTIONS = 101
TIMEOUT_TIME = 40
# axes = [wall_colors]*4 + [object_colors] * 12
# print(axes)
# print("Initial Decorum Puzzle:\n")
# print_decorum(puzzle)
## NOTE with decorum there is no actual "assignment"
class CSP:
def __init__(self, variables, domains, constraints, required_items=None):
self.required_items = required_items
self.variables = variables
self.domains = domains
self.constraints = constraints # I might not actually need this!?
self.domain_changes = [] # This is how I undo domain changes.
self.solution = None
self.timed_out = False
## Generate constraint dictionary
self.var_to_constraints = {var:set() for var in self.variables}
for constraint in self.constraints:
for var in constraint.variables:
self.var_to_constraints[var].add(constraint)
def solve_all(self):
# timeout for setups that are taking too long to calculate
assignment = {}
self.solutions = []
self.end_time = time.time() + TIMEOUT_TIME
# Run domain_update for first time
# OK, so I removed this update_domains call because I want to define domain_updates with var for efficiency.
# Fuck, I actually need this. Because not having the domains updated on the first go may cause us to choose an inefficient first variable. That's no good....
# Ok, if a constraint checks the var assignment and it's still unassigned, then we know that this is a first time run.
# This is super fucking janky, but it's the simplest (and most efficient) solution I can currently think of.
self.update_domains(var=-1, assignment=assignment, ignore_var = True)
self.backtrack(assignment)
self.timed_out = time.time() > self.end_time
return self.solutions, self.timed_out
# Create a method to "solve_all All"
def backtrack(self, assignment):
if time.time() > self.end_time:
return None
if (len(self.solutions) > MAX_SOLUTIONS):
return None
if len(assignment) == len(self.variables):
self.solutions.append(dict(assignment)) # Copy assignment
#print(f"Found Solution #{len(self.solutions)}!")
return None
#print({k:str(v) for k,v in assignment.items()})
#pprint.pprint({k:str(v) for k,v in assignment.items()})
#pprint.pprint(self.domains)
var = self.select_unassigned_variable(assignment)
for value in self.order_domain_values(var, assignment):
assignment[var] = value
if self.is_consistent(var, value, assignment):
self.assign_trigger(var, value, assignment)
# Record old_domains
old_domains = {v:{decor for decor in domain} for v, domain in self.domains.items()}
# Update domains based on assignment (if we're consistent, obviously)
self.update_domains(var, assignment)
result = self.backtrack(assignment)
#if result is not None:
# return result
# Revert domains when we're done.
self.domains = old_domains
self.unassign_trigger(var) # It's odd that this happens before actual unassignment, but AT LEAST CURRENTLY, it doesn't matter.
del assignment[var]
# Don't need to update domains on unassignment if the update only looks at the board state, and not specifically the variable we just changed (which it should.)
return None
def select_unassigned_variable(self, assignment):
unassigned_vars = [var for var in self.variables if var not in assignment]
# Consider "Dynamic MRV" to select variable with minimum domanin based on current assignment
# NOTE: FORCE probably needs to run again if MRV is run.
# MRV AND CONNECTIVITY IMPLEMENTED
return min(unassigned_vars, key=lambda var: len(self.domains[var]) - len(self.var_to_constraints[var])) # Chooses variables based on min domains.
def order_domain_values(self, var, assignment):
# NOTE: I could change domains based on current assignment, limiting the allowed options as I go.
# No need to do any fancy ordering within this function though.
return self.domains[var]
def is_consistent(self, var, val, assignment):
# We only want to check constraints related to this variable
for constraint in self.var_to_constraints[var]:
if not constraint.is_consistent(var, val, assignment):
return False
return True
# def update_domains_with_record(self, var, assignment):
# # Deep copy of domains.
# old_domains = {v:domain for v, domain in self.domains.items()}#{v:{val for val in domain} for v, domain in self.domains.items()}
# self.update_domains(var, assignment)
# # Domain changes is just the difference between old domains and new domains
# # Record it in domain_changes
# domain_changes = {v:old_domains[v]-self.domains[v] for v in self.variables}
# self.domain_changes.append(domain_changes)
def update_domains(self, var, assignment, ignore_var = False):
# Don't record changes. Run for all constraints.
constraint_list = self.constraints if ignore_var else self.var_to_constraints[var]
for constraint in constraint_list:
constraint.update_domain_limitiations(var, assignment, self.domains)
# def revert_domains(self):
# # Revert the domain changes made in this step.
# domains_to_add = self.domain_changes.pop()
# for v, domain_add_set in domains_to_add.items():
# self.domains[v] = self.domains[v] | domain_add_set
def assign_trigger(self, var, val, assignment):
for constraint in self.var_to_constraints[var]:
constraint.on_assign(var, val, assignment)
def unassign_trigger(self, var):
for constraint in self.var_to_constraints[var]:
constraint.on_unassign(var)
if __name__ == "__main__":
variables = [(i) for i in range(16)]
constraints = [
### 1 Three's A Crowd ### (25/50 wins)
# # Yellow
# Exactly2ColorsPerRoom,
# RetroObjectsMostCommon,
# UpstairsAndDownstairsObjectCountMatch,
# # Green
# AtLeast2UniqueStylesPerRoom,
# AllWallColors,
# HouseContainsAllYellowObjects,
# # Blue
# HouseContainsAllRedObjects,
# NoBlueDownstairs,
# AllStylesPresent,
# # Red
# AllWallHangingsExist,
# RedInEveryRoom,
# Exactly4EmptyInHouse,
# # ### 2 Bunkin' ### (35/50 wins)
# # Yellow
# OnlyAntiquesUpstairs,
# EitherUpstairsOrDownstairsHaveRoomPaintedSameColor, # Requires "OR" Operation. Listing things is effectively And, so figure out Or.
# Exactly7Objects,
# # Green
# MoreCoolPaintThanWarm,
# NoIdenticalObjectsOnBothSidesOfHouse,
# AllStylesPresent, # Already Defined
# # Blue
# PaintKitchenRed,
# AtLeastOneRoomOfAllBlueObjects,
# WallHangingsMostCommon,
# # Red
# Exactly1Unusual,
# PaintBathroomBlue,
# EachFloorCannotMatchWallColors,
### 3 CrossTheLine ### (31/50 wins)
# Yellow
# WallOfRoomAboveOrBelowCannotMatchObject, # ???
# YellowObjectsAndBlueWallsInseparable, # ???
# EqualRetroAndAntique,
# # Green
# AllCuriosExist,
# CuriosMatchDiagonallyAdjacentWallColor, # ???
# ColumnsMustHaveExactly0Or2Styles,
# # Blue
# Exactly1EmptyPerRoom,
# ColumnsMustHaveExactly0Or2Objects,
# IfRoomHasGreenObjectPaintRed, # Need Conditional
# # Red
# ContainsEveryModernObject,
# BlueIsMostPrevalent,
# #ColorInclusionConstraint(variables=zone_to_vars[Zone.Object], colors = {1}),
# IfRoomHasUnusualObjectThenPaintGreen, # Need Conditional
# ### 4 Taking Sides ### (28/50 wins)
# # Yellow
# NoRetroInBathroom,
# KitchenFilled,
# NoGreenObjectsOnRightSide,
# # Green
# EvenNumberOfEachStyle,
# NoRedInBathroom,
# BedroomFilled,
# # Blue
# BathroomFilled,
# NoRedInLivingRoom,
# AllColorCountsEqual,
# # Red
# NoRetroInLivingRoom,
# NoGreenPaint,
# NoAntiqueOnRightSide,
### Custom Made Scenarios ##
# Aim for ~20 solutions (10-50)
# Remember, Maximize spread of dependencies AND Difficulty
# Manual Partition #
# Generated Start: [2,1,3,2, 4,0,4, 3,3,0, 0,0,0, 3,3,2]
# ### CUSTOM 1: All Mixed Up ### (28 / 50 wins) # Easy-Medium #
# # A Scenario focused on complex Color and Style dependencies
# # 20 Solutions
# # I would guess 2 stars, there are a lot of solutions, that are notably different, making it seem like it isn't very easy to paint yourself into a corner.
# But the dependencies will likely ensure a couple house meetings of confusion and conflict before people start really understanding what's going on.
# Getting 10 solutions with new setup.instead of 20
# Sus.
# # YELLOW
# Exactly1StylePerColumn, # ! # Maybe write this as "AtMost1StylePerColumn"
# WallsAreExactly2UniqueColors, #@
# NoMoreThan2Curios, #@ # (This is helpful more than hurtful, push player in right direction)
# # GREEN
# Exactly1ColorPerOpposite, # ! # Maybe write this as "AtMost1ColorPerOpposit"
# RightSideHasMoreObjectsThanLeftSide, #&
# MoreWarmPaintThanCoolPaint, #@
# # BLUE
# NoIdenticalObjects, # !$
# HouseContainsAllGreenObjects, # $$@
# LeftSideHasExactly4Objects, #&
# # RED (Ordered for 3P: Yellow, Green, Blue)
# AtLeastTwoObjectsInEveryRoom,#!
# WallsCantMatchRoomObjectColors, #!
# RetroObjectsMostCommon, # !$$
#DirectColorConstraint(colors={1,2}, variables=zone_to_vars[Zone.Upstairs]),
#UniqueDecor(Decor.generate_from_sets(colors=frozenset({2,4}, zones={Zone.WallHanging}, styles={Style.Retro, Style.Modern}), copies=2),
#NoIdenticalInZone(variables=zone_to_vars[Zone.Left]),
#ZoneHasXOrMoreUniqueColors(variables=zone_to_vars[Zone.Object] & zone_to_vars[Zone.Object], min_count=2),
#ZoneHasXOrFewerUniqueColors(variables=zone_to_vars[Zone.Object] & zone_to_vars[Zone.Object], max_count=2),
# ZoneHasXOrMoreEmpties(variables=zone_to_vars[Zone.Object], min_count=9),
# ZoneHasXOrMoreOfXColors(variables=zone_to_vars[Zone.All], colors={1}, min_count=3)
#ZoneHasXOrMoreOfXStyles(variables=zone_to_vars[Zone.Upstairs], styles={Style.Antique}, min_count=4),
# ZoneHasXOrFewerOfXStyles(variables=zone_to_vars[Zone.Object], styles={Style.Antique}, max_count=4),
# ZoneHasXOrMoreOfXSlotType(variables=zone_to_vars[Zone.Object], slot_types={Zone.Lamp}, min_count=3),
# ZoneHasXOrFewerEmpties(variables=zone_to_vars[Zone.Object], max_count=2),
# ZoneHasXOrFewerOfXSlotTypes(variables=zone_to_vars[Zone.Object], max_count=2, slot_types={Zone.Curio}),
# ZoneHasXOrFewerOfXStyles(variables=zone_to_vars[Zone.Object], styles={Style.Modern, Style.Retro}, max_count=0),
#ZonesHaveSameCountOfObjects(zones=[zone_to_vars[Zone.Upstairs], zone_to_vars[Zone.Downstairs]])
# MostCommonSlotTypeInZone(variables=zone_to_vars[Zone.Object], slot_type=Zone.Curio),
# MostCommonColorInZone(variables=zone_to_vars[Zone.Upstairs] & zone_to_vars[Zone.Object], color=4),
# MostCommonStyleInZone(variables=zone_to_vars[Zone.Left], style=Style.Retro),
# ZoneHasXOrMoreUniqueStyles(variables=zone_to_vars[Zone.Object] & zone_to_vars[Zone.Object], min_count=4),
#ZoneHasXOrFewerUniqueStyles(variables=zone_to_vars[Zone.Object] & zone_to_vars[Zone.Object], max_count=2)
# Scenario 2: Carousel (3/50) # VERY HARD #
# 1 Solution
# An Attempt at making a scenario where players actions are dependent on one another circularly, making one person's actions cause another's cause another's.
# A Lot of Adjacency rules.
# # YELLOW
# BathroomColorsMatchBedroomColor,
# BlueIsMostPrevalent,
# RetroObjectsMostCommon,
# #ObjectsComeInPairs,
# # GREEN
# BedroomStylesMatchKitchenStyles,
# AtLeast2UniqueColorsPerRoom,
# AllWallColors,
# # BLUE
# KitchenColorsMatchLivingRoomColor,
# AtLeast2UniqueStylesPerRoom,
# NoWarmPaintOnRightSide,
# # RED
# LivingRoomStylesMatchBathroomStyles,
# NoBlueDownstairs,
# OddNumberOfRedObjects # A collection of other requirements effectively make this required already.
# Scenario 3: Poison Pill
# One Player is given the worst dependencies, other players generally don't conflict with each other, but this one player conflicts with all of them
# Additionally, that player should start the game satisfied.
# Scenario 4: If You Insist <MOST LIKELY HARD>
# There are 9 solutions
# The AI won 4/50 games.
# Manual Constraint Assignment
# Manual Starting Board: [3,2,4,1, 4,3,4, 1,1,3, 1,1,4, 1,2,3]
# Story:
# It's been years since Sam and Isha have remodeled. Their congruent needs make for an easy partnership.
# It is precisely that unyielding stability that attracts the attention of the forest spirits Calliope and Wilmina.
# Can Sam and Isha find a way to co-exist with these new, unpredictable sprites? Or will they need to scrounge up funds for an exorcist?
# # Serious Sam
# # You are encouraged to be kind to Ishan
# # Starts Satisfied, unconditional needs
# EachFloorHasExactly3Styles,
# #NoBlueUpstairs,
# AtLeast2OfEachStyle,
# BedroomColorsMatchKitchenColors,
# # Insistent Ishan
# # You are encouraged to be kind to Sam
# # Starts Satisfied, unconditional needs
# AtLeast4ModernObjects,
# EachSideHasExactly3Colors,
# AllWallColors,
# # Calliope, The Confused (Must go first)
# # OR statements with huge differences.
# # You are encouraged to play up your lack of certainty on what to do.
# ThereCannotBeExactly3ObjectsOfAnyColor, # 4 wrong # 2 wrong
# HouseHasExactly2CuriosOR2Lamps, # always 2 wrong
# BathroomAndLivingRoomAreEitherRedOrBlue, # 2 wrong # 1 wrong
# # Wilmina, The Whimsical (Must go second)
# # You are encouraged to taunt other players when your actions ruin their plans
# # Only conditionals, all of which notably fuck over other players.
# IfRoomHasModernObjectThenHasGreenObject, # 1 instance wrong # 2 wrong
# IfRoomHasBlueObjectThenWallIsCool, # 0 instance wrong # 1 wrong
# IfRoomWallIsWarmRoomHasExactly2Objects, # always 2 wrong
# VV Can add this to make it easier. 20 solutions.
#UniqueDecor(Decor.generate_from_sets(colors={1,2}, styles={Style.Antique, Style.Unusual}, slot_types={Zone.Curio, Zone.WallHanging, Zone.Lamp}))
# # *** Scenario 5: Fine Line <Medium> ***
# # 12 solutions
# # The AI won 17/50 games.
# # Manual Start: [4,2,1,3, 0,4,0, 2,2,0, 1,1,0, 1,0,4]
# # Story:
# # When Belemie, Greggory, Yenna, and Roslin agreed to room togetheer, decorative responsibilities were divied up equally.
# # After all with 4 rooms and 4 different aesthetics, it was obvious how they should split it. Yet, as their tastes evolve, clashes begin.
# # Will they draw new boundaries? Or have they crossed the line?
# # Belemie Blunt - Blue Start Bathroom
# # The ocean's endless maw is rendered in your pristine decor. You yearn for more.
# # The pukish green must go. Erode the lesser colors, until all that remains is the deep.
# # Should Yenna Yor yield to your taste, her sandy decor may remain.
# IfARoomHasBlueItMustHaveAYellowItem,
# BlueIsMostPrevalent,
# NoMoreThan1GreenObjectInHouse,
# # Greggory Grueson - Green Start Kitchen
# # "Greg Grue Green," they call you, on account o' yer takin' a likin' to grass. But heck, yer all grown now.
# # Yeh need mor'n just color. Yeh need *style*. 'Specially if'n yeh wanna impress that there Ms. Rudd.
# Exactly3UnusualOrAntiqueOnRightSide,
# Exactly3UnusualOrModernOnDownstairs,
# GreenAndRedObjectsAreInseparable,
# # Yenna Yor - Yellow Start Bedroom
# # Ugh. Bell's weird. Rosie keeps to herself. You've done so much to balance the decor, and they haven't helped one bit!
# # Even Greg's simple taste has been bulldozed by those bullies. You vow to help carve a slice of the house for himself.
# # Mostly to spite the other two. Mostly. He likes green right?
# NoWarmWallsOnRightSide,
# AtLeast4GreenWallsOrObjects,
# IfGreenWallThenYellowObject,
# # Roslin Rudd - Red Start LivingRoom
# # Day after day, these squacking pidgeons fail to leave you be. Even quiet Belemie has taken to meddling with your trinkets.
# # You ask for so little. In the rouge light of the setting sun, you steel your resolve.
# # This Living room will be yours. These classless parasites will simply have to compromise.
# NoBlueDownstairs,
# OnlyOneStyleInLivingRoom,
# LeftSideHasMoreObjectsThanRightSide,
# Ending:
# In the end, Belemie accepts that, should he wish to remain, the house cannot be flooded with his preferences alone.
# Though only a start, Greggory's venture into styling manages to catch Roslin's attention.
# Yenna's efforts to welcome Greggory were met with warm appreciation, though not quite as much as she'd expected.
# And finally, no one dared to meddle with Roslin's new trinkets. Though each was quite unusual, in a way, they matched the each other perfectly.
# # *** Scenario 6: Fantastic Frames And Where To Find Them ***
# Each Character canonically gets a wild artifact. (Optional added difficulty is that only they may move that artifact)
# Generated Options
# Trash.
# Constraints set with 3 solutions
# ZoneHasXOrFewerUniqueStyles(zone_to_vars[Zone.Bedroom], 2),
# ZoneHasXOrFewerOfXColors(zone_to_vars[Zone.Bedroom], {4}, 2),
# ZonesHaveSameCountOfGivenColorSets((zone_to_vars[Zone.LivingRoom], zone_to_vars[Zone.Bedroom]), ({4}, {1})),
# ZoneHasExactlyXStyleCount(zone_to_vars[Zone.Left], {Style.Unusual}, 2),
# ZonesHaveExactSameStyleCounts((zone_to_vars[Zone.LivingRoom], zone_to_vars[Zone.Kitchen])),
# ZonesHaveSameCountOfObjects((zone_to_vars[Zone.Upstairs], zone_to_vars[Zone.Right])),
# ZonesHaveExactSameColorCounts((zone_to_vars[Zone.Left], zone_to_vars[Zone.Right])),
# ZoneHasExactlyXStyleCount(zone_to_vars[Zone.Object], {Style.Unusual}, 3),
# UniqueDecor(Decor.generate_from_sets(colors={1,2,4}, styles={Style.Unusual}, slot_types={Zone.Lamp})),
# UniqueDecor(Decor.generate_from_sets(colors={3}, styles={Style.Antique, Style.Retro, Style.Modern}, slot_types={Zone.WallHanging})),
# UniqueDecor(Decor.generate_from_sets(colors=set(), styles=set(), slot_types={Zone.WallHanging, Zone.Lamp, Zone.Curio})),
# UniqueDecor(Decor.generate_from_sets(colors={3,4}, styles={Style.Unusual, Style.Retro}, slot_types={Zone.Curio})),
# # UniqueDecor(124U),
# # UniqueDecor(3RAM),
# # UniqueDecor(),
# # UniqueDecor(34UR)
# Constraints set with 34 solutions
# The AI won 12/50 games.
# Kinda Trash? Maybe not?
# ZoneHasXOrFewerOfXColors(zone_to_vars[Zone.Wall], {1}, max_count=1),
# MostCommonSlotTypeInZone(zone_to_vars[Zone.Downstairs], Zone.Curio),
# ZoneHasNoEmptyOrDuplicates(Zone.Lamp),
# ZoneHasOnlyXColors(zone_to_vars[Zone.Left], {0, 2, 3, 4}),
# MostCommonStyleInZone(zone_to_vars[Zone.Object], Style.Modern),
# ZonesHaveExactSameColorCounts((zone_to_vars[Zone.Bathroom], zone_to_vars[Zone.Kitchen])), # This is "fake" difficulty. This and the constraint below make for a very strong requirement that has little to do with the special objects.
# ZonesHaveExactSameColorCounts((zone_to_vars[Zone.Kitchen], zone_to_vars[Zone.LivingRoom])), #
# ZoneHasOnlyXColors(zone_to_vars[Zone.Wall], {0, 2, 3}),
# UniqueDecor(Decor.generate_from_sets(colors={1,2,4}, styles={Style.Unusual}, slot_types={Zone.Lamp})),
# UniqueDecor(Decor.generate_from_sets(colors={3}, styles={Style.Antique, Style.Retro, Style.Modern}, slot_types={Zone.WallHanging})),
# UniqueDecor(Decor.generate_from_sets(colors=set(), styles=set(), slot_types={Zone.WallHanging, Zone.Lamp, Zone.Curio})),
# UniqueDecor(Decor.generate_from_sets(colors={3,4}, styles={Style.Unusual, Style.Retro}, slot_types={Zone.Curio})),
# # UniqueDecor(124U),
# # UniqueDecor(3RAM),
# # UniqueDecor(),
# # UniqueDecor(34UR)
# EitherASideOrFloorMustBeEmpty,
# HouseContainsAtLeast6Objects
#NoIdenticalObjectsOnBothSidesOfHouse,
#HouseContainsAtLeast8Objects, #!@
#AtLeast3Curios,
#KitchenIsBlue,
#BlueIsMostPrevalent,
#Exactly2ColorsPerRoom,
#WallHangingsMostCommon,
#BedroomMustHave3OfTheSameStyle
# # Low dependency score partitions #
# ## Player 1##
# ZonesHaveSameCountOfGivenStyles(({4, 5, 6, 10, 11, 12}, {7, 8, 9, 13, 14, 15}), (Style.Antique, Style.Unusual)),
# ZoneHasXOrFewerOfXColors({10, 2, 11, 12}, {3, 4}, 1),
# ZoneHasExactlyXUniqueColors({0, 1, 2, 3}, 4),
# ## Player 2##
# ZonesHaveExactSameStyleCounts(({13, 14, 15}, {8, 9, 7})),
# ZonesHaveExactSameStyleCounts(({10, 11, 12}, {8, 9, 7})),
# ZonesHaveSameCountOfGivenColorSets(({0, 4, 5, 6}, {3, 13, 14, 15}), (frozenset({1}), frozenset({2}))),
# ## Player 3##
# ZoneHasXOrMoreUniqueStyles({7, 8, 9, 13, 14, 15}, 2),
# ZonesHaveSameCountOfGivenStyles(({13, 14, 15}, {10, 11, 12}), (Style.Antique, Style.Modern)),
# ZoneHasXOrFewerUniqueColors({0, 1, 4, 5, 6, 7, 8, 9}, 2),
# ## Player 4##
# MostCommonSlotTypeInZone({1, 3, 7, 8, 9, 13, 14, 15}, Zone.WallHanging),
# ZoneHasExactlyXUniqueStyles({4, 5, 6, 10, 11, 12}, 4),
# ZoneHasExactlyXUniqueColors({0, 1, 2, 3}, 4),
# 16 Solutions
# The AI won 67/250 games.
# Dependency Optimized Partitions #
# Good Starting Board[3,4,1,1,0,0,4,4,0,0,2,0,0,3,4,0]
# ## Player 1 ##
# ZoneHasXOrMoreUniqueColors({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 4),
# ZoneHasXOrMoreUniqueColors({8, 1, 9, 7}, 3),
# ZoneHasExactlyXUniqueColors({0, 1, 2, 3}, 1),
# ## Player 2 ##
# ZonesHaveExactSameColorCounts(({1, 3, 7, 8, 9, 13, 14, 15}, {0, 1, 4, 5, 6, 7, 8, 9})),
# ZoneHasExactlyXStyleCount({8, 9, 7}, Style.Antique, 1),
# ZoneHasXOrMoreOfXStyle({4, 5, 6, 10, 11, 12}, Style.Retro, 4),
# ## Player 3 ##
# MostCommonStyleInZone({7, 8, 9, 13, 14, 15}, Style.Unusual),
# MostCommonColorInZone({0, 1, 4, 5, 6, 7, 8, 9}, 2),
# ZoneHasExactlyXUniqueColors({10, 2, 11, 12}, 3),
# ## Player 4 ##
# ZoneHasExactlyXStyleCount({7, 8, 9, 13, 14, 15}, Style.Antique, 1),
# AllSlotTypeExist(Zone.Lamp),
# ZoneHasExactlyXUniqueStyles({10, 11, 12}, 2),
# Constraints set with 13 solutions and 19 / 50 wins by simple AI
# Dependency Optimized Partitions #
# Good Starting Board: [1,3,2,4,3,0,0,0,0,0,0,1,1,4,0,0]
## Player 1 ##
# ZoneHasOnlyXColors({4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 4}),
# ZoneHasXOrMoreUniqueColors({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 4),
# MostCommonColorInZone({0, 1, 4, 5, 6, 7, 8, 9}, 1),
# ## Player 2 ##
# ZoneHasXOrFewerOfXColors({4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {3}, 1),
# MostCommonColorInZone({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 2),
# ZoneHasXOrFewerUniqueStyles({13, 14, 15}, 2),
# ## Player 3 ##
# ZoneHasExactlyXUniqueColors({4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 2),
# ZonesHaveSameCountOfGivenColorSets(({0, 2, 4, 5, 6, 10, 11, 12}, {0, 1, 4, 5, 6, 7, 8, 9}), (frozenset({2}), frozenset({3}))),
# ZoneHasXOrFewerUniqueStyles({10, 11, 12, 13, 14, 15}, 3),
# ## Player 4 ##
# ZoneHasXOrFewerOfXStyle({4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, Style.Modern, 1),
# ZoneHasExactlyXUniqueStyles({7, 8, 9, 13, 14, 15}, 3),
# ZoneHasExactlyXUniqueColors({0, 2, 4, 5, 6, 10, 11, 12}, 2),
# # Good one.
# # Constraints set with 24 solutions and 2 / 50 wins by simple AI:
# ZonesHaveExactSameStyleCounts(({10, 11, 12, 13, 14, 15}, {4, 5, 6, 10, 11, 12})),
# ZoneHasXOrMoreUniqueStyles({8, 9, 7}, 3),
# ZonesHaveSameCountOfGivenStyles(({10, 11, 12, 13, 14, 15}, {4, 5, 6, 7, 8, 9}), (frozenset({Style.Unusual}), frozenset({Style.Unusual}))),
# MostCommonColorInZone({0, 2, 4, 5, 6, 10, 11, 12}, 4),
# ZoneHasExactlyXStyleCount({4, 5, 6, 10, 11, 12}, {Style.Antique}, 3),
# ZoneHasExactlyXStyleCount({4, 5, 6, 7, 8, 9}, {Style.Retro}, 2),
# #ZoneHasXOrFewerOfXColors({8, 1, 9, 7}, {4}, 3), # No effect
# ZoneHasXOrMoreOfXColors({0, 1, 2, 3}, {3}, 3),
# ZoneHasXOrMoreUniqueStyles({4, 5, 6, 7, 8, 9}, 4),
# ZonesHaveSameCountOfGivenStyles(({7, 8, 9, 13, 14, 15}, {4, 5, 6, 7, 8, 9}), (frozenset({Style.Antique}), frozenset({Style.Antique}))),
# ZonesHaveSameCountOfObjects(({10, 11, 12, 13, 14, 15}, {4, 5, 6, 10, 11, 12})),
# ZoneHasXOrMoreUniqueStyles({4, 5, 6, 7, 8, 9}, 4),
# UniqueDecor(Decor.generate_from_display_string("13UA#")),
# UniqueDecor(Decor.generate_from_display_string("3#"))
# Constraints set with 239 solutions and 0 / 50 wins by simple AI: ???
# On rerunning this, it timed out. There may be a bug here.
# ZoneHasNoEmptyOrDuplicates(Zone.Wall),
# ZoneHasXOrMoreOfXStyles({4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {Style.Antique}, 1),
# ZoneHasExactlyXColorCount({0, 1, 4, 5, 6, 7, 8, 9}, {3, 4}, 2),
# ZonesHaveExactSameColorCounts(({0, 4, 5, 6}, {3, 13, 14, 15})),
# ZoneHasOnlyXStyles({4, 5, 6, 10, 11, 12}, {Style.Retro, Style.Antique, Style.Modern}),
# ZonesHaveSameCountOfGivenColorSets(({1, 3, 7, 8, 9, 13, 14, 15}, {0, 2, 4, 5, 6, 10, 11, 12}), (frozenset({4}), frozenset({4}))),
# ZoneHasXOrMoreOfXColors({0, 2, 4, 5, 6, 10, 11, 12}, {3}, 1),
# ZoneHasXOrMoreOfXStyles({4, 5, 6, 7, 8, 9}, {Style.Modern}, 4),
# MostCommonStyleInZone({10, 11, 12, 13, 14, 15}, Style.Antique),
# ZonesHaveExactSameColorCounts(({8, 1, 9, 7}, {11, 10, 2, 12})),
# UniqueDecor(Decor.generate_from_display_string("@$#")),
# UniqueDecor(Decor.generate_from_display_string("12AM@")),
# UniqueDecor(Decor.generate_from_display_string("RAUM@")),
# UniqueDecor(Decor.generate_from_display_string("34@"))
# # ***Constraints set with 36 solutions and 17 / 50 wins by simple AI:
# # Could be a good easier one.
# # I like this one.
# # Seems like this one has two solution types:
# # 1) Green wall on bottom right with UA$ lamp. - This seems to have a larger set of solutions.
# # 2) Red Wall on bottom right with 1MUA$ lamp.
# # OOOO I could have No Green in bottom right as an optional bonus points constraint
# # Implement this one for sure. Maybe simplify it a little,
# ZonesHaveSameCountOfGivenStyles(({4, 5, 6, 10, 11, 12}, {7, 8, 9, 13, 14, 15}), (frozenset({Style.Retro}), frozenset({Style.Antique}))),
# ZoneHasXOrFewerOfXStyles({4, 5, 6, 7, 8, 9}, {Style.Retro}, 1),
# MostCommonSlotTypeInZone({0, 2, 4, 5, 6, 10, 11, 12}, Zone.WallHanging),
# MostCommonColorInZone({0, 1, 2, 3}, 2),
# ZoneHasExactlyXUniqueColors({3, 13, 14, 15}, 1),
# ZoneHasExactlyXUniqueStyles({10, 11, 12}, 3), # It's funky that in a decent set of the solutions, the wall is green and the only object in the room is colorless.
# ZoneHasXOrFewerUniqueStyles({4, 5, 6, 10, 11, 12}, 3),
# ZonesHaveSameCountOfObjects(({4, 5, 6}, {13, 14, 15})),
# ZoneHasXOrMoreOfXColors({2, 3, 10, 11, 12, 13, 14, 15}, {3}, 1),
# ZoneHasExactlyXUniqueColors({0, 1, 4, 5, 6, 7, 8, 9}, 2),
# ZonesHaveExactSameColorCounts(({2, 10, 11, 12}, {1, 7, 8, 9})),
# # #ColorExclusionConstraint({3,13,14,15}, {3}) # Bonus Points
# UniqueDecor(Decor.generate_from_display_string("1UAM$")),
# UniqueDecor(Decor.generate_from_display_string("2RM$")),
# UniqueDecor(Decor.generate_from_display_string("UA$")),
# UniqueDecor(Decor.generate_from_display_string("RM#"))
# # There are the same number of Retro objects on the left as there are Antique objects on the right
# # There is no more than 1 retro object upstairs
# # Wall Hangings are the most common object type on the left
# # The most common wall color is yellow
# # There is exactly 1 unique color in the Kitchen (walls / objects)
# # There is exactly 3 unique styles in the Living Room
# # There are no more than 3 unique styles on the left side
# # There is at least 1 green downstairs (walls / objects)
# # There is exactly 2 unique colors upstairs (walls / objects)
# # The Living Room and Bedroom have the same count of all colors (walls / objects)
# # There are 4 unique objects that cannot be removed:
# # A Red Lamp fusing Modern, Antique, and Unusual styles
# # A Yellow Lamp contrasting Retro with Modern
# # A Monochrome, Unusual, Antique Lamp
# # A Monochrome, Retro, Modern Wall Hanging
# # Constraints set with 60 solutions and 0 / 50 wins by simple AI:
# ZoneHasXOrMoreUniqueStyles({4, 5, 6}, 2),
# ZonesHaveSameCountOfGivenColorSets(({3, 13, 14, 15}, {8, 1, 9, 7}), (frozenset({4}), frozenset({0}))),
# ZonesHaveSameCountOfObjects(({7, 8, 9, 13, 14, 15}, {10, 11, 12, 13, 14, 15})),
# ZoneHasExactlyXStyleCount({13, 14, 15}, {Style.Modern}, 0),
# ZoneHasXOrFewerUniqueColors({0, 1, 4, 5, 6, 7, 8, 9}, 1),
# ZoneHasXOrFewerUniqueColors({0, 4, 5, 6}, 2),
# ZoneHasXOrFewerOfXStyles({4, 5, 6, 7, 8, 9}, {Style.Modern}, 2),
# MostCommonColorInZone({0, 1, 2, 3}, 3),
# ColorInclusionConstraint({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {1, 3, 4}),
# ZoneHasNoEmptyOrDuplicates(Zone.Wall), # This isn't meant to be done to walls.
# ZonesHaveSameCountOfGivenStyles(({10, 11, 12}, {8, 9, 7}), (frozenset({Style.Modern}), frozenset({Style.Modern}))),
# ZoneHasXOrMoreUniqueStyles({4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 2),
# UniqueDecor(Decor.generate_from_display_string("23R#")),
# UniqueDecor(Decor.generate_from_display_string("23M$"))
# # Constraints set with 1 solutions and 0 / 50 wins by simple AI:
# # Odd one.
# MostCommonColorInZone({1, 3, 7, 8, 9, 13, 14, 15}, 2),
# ZonesHaveSameCountOfObjects(({10, 11, 12, 13, 14, 15}, {4, 5, 6, 7, 8, 9})),
# MostCommonColorInZone({0, 1, 4, 5, 6, 7, 8, 9}, 4),
# ZoneHasXOrMoreOfXColors({3, 13, 14, 15}, {1, 2}, 2),
# ZoneHasXOrFewerUniqueColors({0, 2, 4, 5, 6, 10, 11, 12}, 1),
# ZoneHasXOrMoreOfXColors({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {4}, 1),
# ZonesHaveSameCountOfGivenStyles(({4, 5, 6, 10, 11, 12}, {4, 5, 6, 7, 8, 9}), (frozenset({Style.Retro}), frozenset({Style.Retro}))),
# ZoneHasNoEmptyOrDuplicates(Zone.Lamp),
# ZoneHasNoEmptyOrDuplicates(Zone.Wall),
# MostCommonStyleInZone({7, 8, 9, 13, 14, 15}, Style.Modern),
# ZoneHasXOrMoreOfXColors({0, 1, 4, 5, 6, 7, 8, 9}, {1}, 3),
# UniqueDecor(Decor.generate_from_display_string("$#@")),
# UniqueDecor(Decor.generate_from_display_string("2#"))
# # Constraints set with 24 solutions and 6 / 50 wins by simple AI:
# ZoneHasXOrMoreUniqueColors({1, 3, 7, 8, 9, 13, 14, 15}, 1),
# MostCommonColorInZone({1, 3, 7, 8, 9, 13, 14, 15}, 3),
# ZonesHaveExactSameStyleCounts(({4, 5, 6, 10, 11, 12}, {7, 8, 9, 13, 14, 15})),
# ZonesHaveExactSameColorCounts(({3, 13, 14, 15}, {0, 4, 5, 6})),
# ZoneHasExactlyXUniqueColors({0, 1, 2, 3}, 4),
# ZonesHaveExactSameStyleCounts(({4, 5, 6, 7, 8, 9}, {7, 8, 9, 13, 14, 15})),
# ZonesHaveExactSameStyleCounts(({13, 14, 15}, {10, 11, 12})),
# ZoneHasXOrFewerOfXColors({0, 4, 5, 6}, {4}, 0),
# UniqueDecor(Decor.generate_from_display_string("14#")),
# UniqueDecor(Decor.generate_from_display_string("4UA$"))
# Try 1252: Constraints set with 204 solutions and 19 / 50 wins by simple AI:
# ZoneHasXOrMoreOfXStyles({4, 5, 6, 7, 8, 9}, {Style.Unusual}, 3),
# ZoneHasXOrFewerUniqueStyles({10, 11, 12}, 1),
# ZoneHasExactlyXUniqueStyles({8, 9, 7}, 2),
# ColumnsMustHaveExactly0Or2Styles,
# ZoneHasXOrMoreOfXColors({4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {3, 4}, 6), # For Harder: ZoneHasExactlyXOfXColors({3,4}, 4)
# ZoneXHasMoreColorCThanZoneY([{8, 1, 9, 7}, {2, 3, 10, 11, 12, 13, 14, 15}], {2}),
# MostCommonColorInZone({0, 1, 4, 5, 6, 7, 8, 9}, 1),
# ThereCannotBeExactly3ObjectsOfAnyColor,
# UniqueDecor(Decor.generate_from_display_string("23@")),
# UniqueDecor(Decor.generate_from_display_string("4@")),
# UniqueDecor(Decor.generate_from_display_string("14R@")),
# UniqueDecor(Decor.generate_from_display_string("3$"))
# #Try 3228: Constraints set with 24 solutions and 0 / 50 wins by simple AI:
# # This one's funky
# ZoneHasXOrFewerUniqueStyles({4, 5, 6}, 1),
# MostCommonColorInZone({0, 1, 2, 3}, 1),
# ZonesHaveSameCountOfObjects([{0, 4, 5, 6}, {8, 1, 9, 7}]),
# ZonesHaveSameCountOfGivenStyles([{4, 5, 6}, {10, 11, 12}], [frozenset({Style.Antique}), frozenset({Style.Retro})]),
# ZonesHaveSameCountOfGivenStyles([{7, 8, 9}, {13, 14, 15}], [frozenset({Style.Retro}), frozenset({Style.Antique})]),
# ZonesHaveExactSameColorCounts([{10, 2, 11, 12}, {3, 13, 14, 15}]),
# ZoneHasXOrFewerOfXColors({1, 3, 7, 8, 9, 13, 14, 15}, {1}, 1),
# #ZoneHasXOrMoreOfXStyles({13, 14, 15}, {Style.Antique}, 3),
# AtLeastOneOFEachSlotTypeWithGivenStyle(Style.Retro),
# #AtLeastOneOFEachSlotTypeWithGivenStyle(Style.Antique),
# ZoneHasXOrFewerOfXStyles(zone_to_vars[Zone.Object], {Style.Modern, Style.Unusual}, 2),
# UniqueDecor(Decor.generate_from_display_string("2RAM#")),
# UniqueDecor(Decor.generate_from_display_string("2#")),
# UniqueDecor(Decor.generate_from_display_string("34#")),
# UniqueDecor(Decor.generate_from_display_string("14U#"))
# # Try 25: Constraints set with 18 solutions and 0 / 50 wins by simple AI:
# # This one's also fun after a couple tweaks :)
# AtLeast2OfEachStyle,
# AtLeastTwoObjectsInEveryRoom,
# MostCommonColorInZone({0, 2, 4, 5, 6, 10, 11, 12}, 1),
# AtLeastOneOFEachSlotTypeWithGivenStyle(Style.Antique),
# ZonesHaveExactSameStyleCounts([{10, 11, 12}, {13, 14, 15}]),
# ZoneHasXOrFewerOfXColors({0, 1, 4, 5, 6, 7, 8, 9}, {1}, 2),
# ZoneHasExactlyXUniqueStyles({7, 8, 9, 13, 14, 15}, 3),
# ZoneHasXOrFewerUniqueColors({1, 3, 7, 8, 9, 13, 14, 15}, 1),
# UniqueDecor(Decor.generate_from_display_string("234M#")),
# UniqueDecor(Decor.generate_from_display_string("#$@"))
#Try 1572: Constraints set with 21 solutions and 40 / 50 wins by simple AI:
# Interesting!
# AtLeast2OfEachStyle,
# EachFloorCannotMatchWallColors,
# ZoneHasXOrMoreOfXStyles({10, 11, 12, 13, 14, 15}, {Style.Antique}, 4),
# ZoneHasXOrFewerUniqueStyles({10, 11, 12, 13, 14, 15}, 2),
# NoAdjacentSameColor,
# EachFloorCannotMatchWallColors,
# MostCommonStyleInZone({4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, Style.Unusual),
# UniqueDecor(Decor.generate_from_display_string("2RM$"))
# # Try 629: Constraints set with 21 solutions and 10 / 50 wins by simple AI:
# **** This one's a gem.
# Not only does it feel pretty unique. It incorporates walls well
# Despite smaller and fairly simple constraint set it feels interesting to sort out.
# It has a nice extra challenge mode too.
# The use of the unique artwork is also quite fun.
ZoneHasXOrMoreOfXStyles({4, 5, 6}, {Style.Unusual}, 3),
StyleExclusionConstraint({8, 9, 7}, {Style.Modern}),
MostCommonColorInZone({2, 3, 10, 11, 12, 13, 14, 15}, 4),
EachSideHasExactly3Colors,
ZoneHasExactlyXUniqueColors({4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 3),
ZoneHasXOrFewerUniqueColors({8, 1, 9, 7}, 1),
AllColorCountsEqual,
ZoneHasXOrMoreUniqueColors({0, 2, 4, 5, 6, 10, 11, 12}, 3),
UniqueDecor(Decor.generate_from_display_string("3UR@")),
UniqueDecor(Decor.generate_from_display_string("M#")),
# !!!! Extra Challenge: (6 solutions)
# ZoneHasXOrFewerOfXColors({7,8,9}, {0}, 2)
]
# Generate typical allowed values
domains = {}
for var in variables:
if puzzle[var] != -1:
domains[var] = {puzzle[var]}
else:
domains[var] = set()
for color_ind in [1,2,3,4]:
allowed_decor = Decor.generate_common_artwork(var, color_ind)
#print(allowed_decor.eq_val)
domains[var].add(allowed_decor)
if var>=4: # Isn't a wall
domains[var].add(None) # Empty
# Add Unique Decor
for constraint in constraints:
if isinstance(constraint, UniqueDecor):
# Add domains.
for var in constraint.variables:
domains[var].add(constraint.decor)
#print(domains)
csp = CSP(variables, domains, constraints)
from cProfile import Profile
from pstats import SortKey, Stats
with Profile() as profile:
print(f"{csp.solve_all() = }")
(
Stats(profile)
.strip_dirs()
.sort_stats(SortKey.TIME)
.print_stats()
)
timed_out = csp.timed_out
sol = csp.solutions
print(f"\n******* Found {len(sol)} Solutions *******\n")
if timed_out:
print("But there are likely more solutions as we timed out.")
show_amount = min(10, len(sol))
print (f"Here are the first {show_amount}.")
for _ in range(show_amount):
print_decorum(random.choice(sol))
# recurse(curr_house, 0,possible_houses)
# Extensions I can try:
# Identifying the symmetries available in the solutions
# Generating my own Rules.