This commit is contained in:
Nemo D'ACREMONT 2025-05-18 20:02:38 +02:00
parent 91cf372a7e
commit 22dfbcbbc1
No known key found for this signature in database
GPG Key ID: 85F245EC3BB1E022
5 changed files with 23 additions and 7 deletions

View File

@ -4,3 +4,5 @@ __pycache__
/go-package.tgz /go-package.tgz
*.ipynb *.ipynb
/chess /chess
/tp_player-ndacremont_meyben
/tp_player-ndacremont_meyben.tar.gz

View File

@ -12,15 +12,13 @@ files += tp_player-ndacremont_meyben/requirements.txt
.PHONY += all .PHONY += all
all: tp_player-ndacremont_meyben.tar.gz all: tp_player-ndacremont_meyben.tar.gz
tp_player-ndacremont_meyben.tar.gz: tp_player-ndacremont_meyben $(files) tp_player-ndacremont_meyben.tar.gz: $(files)
tar -cvzf $@ $^ tar -cvzf $@ $^
tp_player-ndacremont_meyben/%: % tp_player-ndacremont_meyben/%: %
@mkdir -p $(dir $@)
cp $^ $@ cp $^ $@
tp_player-ndacremont_meyben:
mkdir -p $@
.PHONY += clean .PHONY += clean
clean: clean:
$(RM) -r tp_player-ndacremont_meyben tp_player-ndacremont_meyben.tar.gz $(RM) -r tp_player-ndacremont_meyben tp_player-ndacremont_meyben.tar.gz

View File

@ -1,5 +1,21 @@
# TP Noté joueur Go -- Nemo D'ACREMONT, Martin EYBEN, G1 # TP Noté joueur Go -- Nemo D'ACREMONT, Martin EYBEN, G1
## Librairies nécessaire
Ces librairies sont listées dans le fichier `requirements.txt` et sont les
suivantes :
* PyTorch
* Numpy
## Techniques utilisées
* IDDFS avec alphabeta
* Stop le calcule du coup dans le parcours alphabeta si on dépasse le temps
alloué
* Joue des coups classiques sans heuristique lorsqu'il y a peu (<10) de pions
sur le plateau
* Passe si le joueur l'adversaire vient de passer et qu'on est en train de
gagner
* Plus de pions sont joués, plus on alloue du temps à jouer, sauf si on est
proche de 30min, dans quel cas on joue rapidement

View File

@ -97,7 +97,6 @@ def IDDFS(
shouldStop = lambda: (time.time() - start_time) >= duration shouldStop = lambda: (time.time() - start_time) >= duration
for depth in range(1, max_depth + 1): for depth in range(1, max_depth + 1):
value, move = _alphabeta( value, move = _alphabeta(
board, heuristic=heuristic, color=color, depth=depth, shouldStop=shouldStop board, heuristic=heuristic, color=color, depth=depth, shouldStop=shouldStop
) )

View File

@ -49,7 +49,8 @@ def goban2Go(board: Goban.Board):
goBoard[2, :, :] = 1 if black_plays else 0 goBoard[2, :, :] = 1 if black_plays else 0
return goBoard # sometime, a little bit of magic is required
return torch.from_numpy(np.array([goBoard])).float()
class GoModel(nn.Module): class GoModel(nn.Module):
@ -154,7 +155,7 @@ class myPlayer(PlayerInterface):
return math.inf if board.winner() == self._mycolor else -math.inf return math.inf if board.winner() == self._mycolor else -math.inf
go_board = torch.from_numpy(np.array([goban2Go(board)])).float().to(self.device) go_board = goban2Go(board).to(self.device)
self.model.eval() self.model.eval()
with torch.no_grad(): with torch.no_grad():