Pseudosphere

Joined 16 January 2024
3,017 bytes added ,  08:51, 25 March 2024
no edit summary
Line 410: Line 410:  
table.compile("calc", mwcollapse.genStateMachine(("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "add", "sub", "mul", "div", "equ", "AC"), transition, stategen, (-1, None, -1)))
 
table.compile("calc", mwcollapse.genStateMachine(("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "add", "sub", "mul", "div", "equ", "AC"), transition, stategen, (-1, None, -1)))
 
print(table)
 
print(table)
 +
</syntaxhighlight>
 +
===[[Notakto]] generator===
 +
<syntaxhighlight lang="python">
 +
#!/bin/python3
 +
import mwcollapse
 +
 +
boot = (49, 82, 148, 280, 49, 82, 148, 280)
 +
 +
class State:
 +
    __slots__ = "state", "bools", "transition"
 +
    def __init__(self, state, transition=None):
 +
        self.state = state
 +
        self.bools = tuple((state & 1 << n) != 0 for n in range(9) if n != 4)
 +
        self.transition = transition
 +
    def __eq__(self, other):
 +
        return self.state == other.state
 +
    def __hash__(self):
 +
        return self.state
 +
    def __len__(self):
 +
        return self.bools.count(True)
 +
    def __getitem__(self, key):
 +
        return True if key == None or key == ... else self.bools[key]
 +
    def gameover(self):
 +
        return (self.bools[0] and self.bools[1] and self.bools[2]) or (self.bools[0] and self.bools[3] and self.bools[5]) or (self.bools[0] and self.bools[7]) or (self.bools[1] and self.bools[6]) or (self.bools[2] and self.bools[5]) or (self.bools[2] and self.bools[4] and self.bools[7]) or (self.bools[3] and self.bools[4]) or (self.bools[5] and self.bools[6] and self.bools[7])
 +
 +
varToPos = lambda n: n if n < 4 else n + 1
 +
posToVar = lambda n: n if n < 4 else n - 1
 +
 +
def transition(state, transition):
 +
    if not state[0].gameover():
 +
        if not state[1]:
 +
            if transition == None:
 +
                if len(state[0]) == 1:
 +
                    return State(boot[state[0].transition]), True, False
 +
                for n in range(9):
 +
                    if not state[0][n]:
 +
                        s = State(state[0].state | 1 << varToPos(n))
 +
                        if not s.gameover():
 +
                            return s, True, False
 +
        elif not state[0][transition]:
 +
            s = State(state[0].state | 1 << varToPos(transition), transition)
 +
            return s, False, s.gameover()
 +
    elif transition == ...:
 +
        return (State(0b000010000), True, False)
 +
    return None
 +
e = mwcollapse.ElementContainer(
 +
    '<p style="text-align: center;">',
 +
    mwcollapse.Trigger("span", None, "End turn", attributes={"class": "nimbutton"}),
 +
    mwcollapse.Collapsible("span", 8, "End turn", attributes={"class": "nobutton"}),
 +
    mwcollapse.Trigger("span", ..., "Try again", attributes={"class": "nimbutton"}),
 +
    '</p><table class="tictactoe">',
 +
    *(mwcollapse.Element("tr",
 +
        *(mwcollapse.Element("td",
 +
            '<span class="cell">X</span>' if k == 4 else mwcollapse.ElementContainer(
 +
                mwcollapse.Trigger("span", posToVar(k), attributes={"class": "cell"}),
 +
                mwcollapse.Collapsible("span", posToVar(k), "X", attributes={"class": "cell"})
 +
            ),
 +
        ) for k in range(n, n + 3))
 +
    ) for n in (0, 3, 6)),
 +
    "</table>",
 +
    mwcollapse.Collapsible("p", 9, "YOU LOSE", attributes={"style": "font-size: 500%; font-weight: bold; text-align: center;"})
 +
)
 +
e.compile("notakto", mwcollapse.genStateMachine((*range(8), None, ...), transition, lambda state: (*state[0].bools, state[1], state[2]), (State(0b000010000), True, False)))
 +
print(e)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
==Kepler–Poinsot polyhedra==
 
==Kepler–Poinsot polyhedra==
1,154

edits