From 6cc2d845199ffbff011ba9d61d0fb31285da3b94 Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Fri, 15 Apr 2022 01:52:22 +0200 Subject: [PATCH] BrokeBrokenn --- brains/uttt.pth | Bin 5327 -> 6287 bytes ultimatetictactoe.py | 38 ++++++++++++++++---------------------- vacuumDecay.py | 20 ++++++++++++++------ 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/brains/uttt.pth b/brains/uttt.pth index edcaf6fc632409066c81cef7bb60d3043ddc7a59..eae2edd1729db3cd7334e66299edbb92a68d8aed 100644 GIT binary patch delta 4375 zcmZWs2UJwo)}Fzkw`mL=h9(0HLy;oRJ+ndVh!hn?QK~ds#v1FuAfR9)V*mwFLLa&NN^!82=@Rw9pr-pDI%;^#9(PwSG&~{-1|@<~n(7 zdRQ29>CFFOBjmHz$!C9!`N`wf$>)5H`OD|7lgEF-mM=|`M26|=S)a3+UO9}xs2ryH zq;1D{Vk9m}PS02|&nqQyS)!NsxY70u)vu=ZiV>N{M16=0c8`w9Hl6e#mn?2*tUeFO zJl;(tlb0RQr0UV|N;4slh%ZSl~&lbA3tg$_$8KJ(m0dNhF^f)ZEL;P>^d%BCC=N z$i`(#$OM)JA$OArWAi;(`fpAU&|;zqtq&#*lRRWGl}4y(Osy=qCK?|O_A0l$Z)ZOXQRiHi}!+naW(-0b!>^h!jCi*%n#aO>qsmg zxsz|&i)HOf#Td?BFhRCT_15dpNx1G1D($rp6uH&r8KYbYI zwHcwc<9(=`!pZamTaEhUhEvjeXG^3vE(9WeW)|j)7gFCu<)ek&Iq3JcEZpuHO!sfC zLKQ#$NPV7k94!!>qaQe6eCLoOvYN`rI5kI|IbcrD@a?8g*XN_v>JQYdThVAkauA+% zJRUPfRgU@?y#W2H%~hcHZDM?(E&`Ql+oOp6FX;_GU8n2{r=ph~%~Ybt18KKr3igcM zhRQ4+QENkYBSV+t)aUQq(QGX)GTG;aHl|hJ&tBO$&v7M9r77qF#6xiw1+;RD674E2 zK|Ab1v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b2OH@TJU7u#Q#$ z*>66Qh&S%X!gtYdC|O#}C#@kaYbFf(jDskg(+V!qzuc6#S|}V=!iRVFNRFh-z+0ap zNXXlbW7>_-5ZZ))I;fI0Te|5w_YJV`&w6MGuY=VAiS%T=3tVSQ$s+Sg3>lc}$nE#T z^Gl*Z<4z0&y82;-cRP8I*o=u6vWP(T1o5laX6hAk;rip{FuFZZ1ZT2xB;=(QYTq?v zrUd1}5U(8E)~BHCC3R-;mMKig#l7Ty?+W^fNS`_MM*#{R{z^MqN+BKZ&}(jnsOnb) zUm5!G-b7}@r&0Il>}iJ_1FNs$@1756+uFve@4+O2i{!MZr<;N(mKy{%xT|GNBL7xeQloO6z5JXsnf>2In~$^G83KL zI%#gP4lFL|$3BiC+caK>=S8pmF;`|QIGt6;mwx-eX&?_bK?uY|C4%1~brNZmOYU~$ zVsqAB@`Y|7Z{+F}wr{+c7|!k@U}DJf&X!@y$V=pID?sk*`#6+*o&NEu0PU*s$+}t9 zcvCk9f8+FE;V){<`H5`AUix~n9$I37bUv~7_w#ZsafQB#@x+d$cMi@(|1g5Fw)lp=qimtJ e*x0~HM@L8MAZ=cJMWu=77G3dHgDHxCng0VzO$bo{ diff --git a/ultimatetictactoe.py b/ultimatetictactoe.py index 585136b..57e3e1f 100644 --- a/ultimatetictactoe.py +++ b/ultimatetictactoe.py @@ -127,7 +127,11 @@ class TTTState(State): def getTensor(self, player=None, phase='default'): if player==None: player = self.curPlayer - return torch.tensor([self.symbToNum(b) for b in self.board]) + s = '' + for row in range(1, 10): + for col in range(1, 10): + s += self.board[self.index(row, col)] + return torch.tensor([self.symbToNum(b) for b in s]) @classmethod def getModel(cls, phase='default'): @@ -138,8 +142,7 @@ class Model(nn.Module): super().__init__() self.smolChan = 12 - self.bigChan = 5 - self.compChan = 3 + self.compChan = 7 self.smol = nn.Sequential( nn.Conv2d( @@ -152,35 +155,26 @@ class Model(nn.Module): nn.ReLU() ) self.big = nn.Sequential( - nn.Conv2d( - in_channels=self.smolChan, - out_channels=self.bigChan, - kernel_size=(3,3), - stride=3, - padding=0, - ), - nn.ReLU() - ) - self.out = nn.Sequential( - #nn.Linear(bigChan, 1), - nn.Linear(self.bigChan, self.compChan), + nn.Linear(self.smolChan*9, self.compChan), + #nn.ReLU(), + #nn.Linear(self.compChan, 1), nn.ReLU(), - nn.Linear(self.compChan, 1), + nn.Linear(self.compChan, 3), + nn.ReLU(), + nn.Linear(3, 1), nn.Sigmoid() ) def forward(self, x): x = torch.reshape(x, (1,9,9)) x = self.smol(x) - x = self.big(x) - x = torch.reshape(x, (self.bigChan,)) - #x = x.view(x.size(0), -1) - y = self.out(x) + x = torch.reshape(x, (self.smolChan*9,)) + y = self.big(x) return y if __name__=="__main__": run = NeuralRuntime(TTTState()) run.game(None, 4) - #trainer = Trainer(TTTState()) - #trainer.train() + trainer = Trainer(TTTState()) + trainer.train() diff --git a/vacuumDecay.py b/vacuumDecay.py index 05b1096..1fa68d9 100644 --- a/vacuumDecay.py +++ b/vacuumDecay.py @@ -186,6 +186,8 @@ class Node(): def _expand(self): self._childs = [] + if self.getWinner()!=None: + return actions = self.state.getAvaibleActions() for action in actions: newNode = Node(self.state.mutate(action), self.universe, self, action) @@ -284,11 +286,17 @@ class Node(): self._calcScore(p) def _calcScore(self, player): + winner = self.getWinner() + if winner!=None: + if winner==player: + self._scores[player] = 0.0 + else: + self._scores[player] = 1.0 + return if self.universe.scoreProvider == 'naive': self._scores[player] = self.state.getScoreFor(player) elif self.universe.scoreProvider == 'neural': self._scores[player] = self.state.getScoreNeural(self.universe.model, player) - else: raise Exception('Uknown Score-Provider') @@ -329,7 +337,7 @@ class Node(): s.append("[ -> "+str(self.lastAction)+" ]") s.append("[ turn: "+str(self.state.curPlayer)+" ]") s.append(str(self.state)) - s.append("[ score: "+str(self.getStrongFor(self.state.curPlayer))+" ]") + s.append("[ score: "+str(self.getScoreFor(0))+" ]") return '\n'.join(s) def choose(txt, options): @@ -452,7 +460,7 @@ class Trainer(Runtime): self.rootNode = Node(initState, universe = self.universe) self.terminal = None - def buildDatasetFromModel(self, model, depth=4, refining=False): + def buildDatasetFromModel(self, model, depth=4, refining=True): print('[*] Building Timeline') term = self.linearPlay(model, calcDepth=depth) if refining: @@ -462,8 +470,8 @@ class Trainer(Runtime): self.fanOut(term.parent.parent, depth=depth+1) return term - def fanOut(self, head, depth=10): - for d in range(max(3, depth-3)): + def fanOut(self, head, depth=4): + for d in range(max(1, depth-2)): head = head.parent head.forceStrong(depth) @@ -499,7 +507,7 @@ class Trainer(Runtime): loss_func = nn.MSELoss() optimizer = optim.Adam(model.parameters(), lr) term = self.buildDatasetFromModel(model, depth=calcDepth) - for r in range(16): + for r in range(64): loss_sum = 0 zeroLen = 0 for i, node in enumerate(self.timelineIter(term)):