Giter Site home page Giter Site logo

atw1020 / sente Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 3.0 9.01 MB

Sente is an open source python library for the game of Go

Home Page: https://sente.readthedocs.io/en/latest/index.html

License: MIT License

Python 39.92% C++ 59.50% C 0.03% Meson 0.56%
go-game python3 python sgf-parsing sgf sgf-files pip baduk weiqi igo

sente's People

Contributors

atw1020 avatar dependabot[bot] avatar norabelrose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sente's Issues

pip installation not working in sente 0.4.3

There seems to be an issue with wheel distribution in sense 0.4.3 that causes pip to be unable to install meson. For the present, please use 0.4.2 until this gets resolved

game.get_sequence() result like on sgf file

game.play(4, 4)
game.play(4, 15)
game.play(15, 15)
print(game.get_sequence())

result

[<sente.Move B[dd]>, <sente.Move W[do]>, <sente.Move B[oo]>]

expected result like on sgf file, more human readable

B[dd];W[do];B[oo]

question
how to achieve it in sente ?

thanks and best regards,

game.get_results() like on sgf file

print('Result :', game.get_results() )

result

Result : <sente.result "W+R">

expected result like on sgf file, more human readable

Result : W+R

question
how to achieve it in sente ?

thanks and best regards,

No such file or directory: 'version.txt'

With Python 3.11, in a Conda environment, I get this:

$ pip install sente
Collecting sente
  Using cached sente-0.4.2.tar.gz (6.1 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [10 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-zeg2uwrv/sente_c6b6c3dd27b84e27b21796071647bc83/setup.py", line 135, in <module>
          version=read_file("version.txt").strip(),
                  ^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-install-zeg2uwrv/sente_c6b6c3dd27b84e27b21796071647bc83/setup.py", line 128, in read_file
          with open(filename, encoding="utf-8") as file:
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      FileNotFoundError: [Errno 2] No such file or directory: 'version.txt'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

The file, used by setup.py, is not included within the package served for example here: https://pypi.org/project/sente/#files so to me it seems like this is just a problem of file not being included by accident.

an example code how to make it a game human vs comp or human vs human

on python module chess https://github.com/niklasf/python-chess, the owner include the link for example how to create their creation useful with a game human vs comp or human vs human
https://jupyter.brynmawr.edu/services/public/dblank/CS371%20Cognitive%20Science/2016-Fall/Programming%20a%20Chess%20Player.ipynb

perhaps sente have another example how to achieve it
tried before base on python chess notebook link above but my problem is when the human player turn input, it's hard to map it into sente move
e.g. using move = input("Move : "), when type 4,4 the machine think it's as string
when separate it
x = int(input("X : ") )
y = int(input("Y : ") )
move = x, y
then it still raise an error

Require Sabaki to jump to a certain node

Awesome package! Thank you so much for implementing sente. Plus, the documentation is clearly written. I'm very excited!

As discussed here, I'm trying to use sente to ask Sabaki to jump to a specific node of a specific sgf file. While sente can serve as an AI (after implementing our own genmove()), I'm certain that it won't be hard to achieve my goal. Would you mind sharing how?

sgf replay can't get game.get_winner()

tested on colab and jupyter (localhost)

def random_player(game):
    move = random.choice(list(game.get_legal_moves() ) )
    return move

def play_game(player1, player2):
    game = sente.Game(9, sente.rules.JAPANESE)
    try:
        while not game.is_over():
            move = random_player(game)
            game.play(move)
            clear_output(wait = True)
            print(game)
    except KeyboardInterrupt:
        msg = "Game interrupted!"
        return (None, msg, game)
    file_sgf = "sgf/sente-random_player.sgf"
    sgf.dump(game, file_sgf)
    print('Winner :', game.get_winner() )

def play_sgf(file_sgf):
    game = sgf.load(file_sgf)
    try:
        for move in game.get_default_sequence():
            game.play(move)
            clear_output(wait = True)
            print(game)
    except KeyboardInterrupt:
        msg = "Game interrupted!"
        return (None, msg, game)
    print('File :', file_sgf)
    print('Winner :', game.get_winner() )

then run to record the game into *.sgf

play_game(random_player, random_player)

result you can see the winner

edit the "sgf/sente-random_player.sgf" using temporary solution on issue/1

and to replay previous game recorded

play_sgf("sgf/sente-random_player.sgf")

result not expected

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-52-8fbc0def84c5> in <module>
----> 1 play_sgf("sgf/sente-random_player.sgf", pause = 0.0)

<ipython-input-51-e2defd67b697> in play_sgf(file_sgf, pause)
---> 37     print('Winner :', game.get_winner() )
     38 

ValueError: could not get results of game, the game is still ongoing

temporary solution, to get the winner or result is by extract the metadata,
but what's going on,
the function of play_sgf() is to replay the *.sgf file, then expected result is must be same when playing it using play_game() function

best regards

generated sgf File did not perfectly match SGF format

tested on colab and jupyter (localhost)

def random_player(game):
    move = random.choice(list(game.get_legal_moves() ) )
    return move

def play_game(player1, player2):
    game = sente.Game(9, sente.rules.JAPANESE)
    try:
        while not game.is_over():
            move = random_player(game)
            game.play(move)
            clear_output(wait = True)
            print(game)
    except KeyboardInterrupt:
        msg = "Game interrupted!"
        return (None, msg, game)
    file_sgf = "sgf/sente-random_player.sgf"
    sgf.dump(game, file_sgf)
    print('Winner :', game.get_winner() )

def play_sgf(file_sgf):
    game = sgf.load(file_sgf)
    try:
        for move in game.get_default_sequence():
            game.play(move)
            clear_output(wait = True)
            print(game)
    except KeyboardInterrupt:
        msg = "Game interrupted!"
        return (None, msg, game)
    print('File :', file_sgf)
    print(sgf.get_metadata(file_sgf) )

then run to record the game into *.sgf

play_game(random_player, random_player)

and to replay previous game recorded

play_sgf("sgf/sente-random_player.sgf")

error traceback when execute play_sgf("sgf/sente-random_player.sgf")

---------------------------------------------------------------------------
InvalidSGFException                       Traceback (most recent call last)
<ipython-input-27-1d5c168b0a27> in <module>
----> 1 play_sgf("sgf/sente-random_player.sgf")

<ipython-input-26-da610c86d202> in play_sgf(file_sgf)
      1 def play_sgf(file_sgf):
----> 2     game = sgf.load(file_sgf)
      3     try:
      4         for move in game.get_default_sequence():
      5             game.play(move)

InvalidSGFException: File did not perfectly match SGF format

temporary solution is to edit "sgf/sente-random_player.sgf"
e.g.
;B[df];W[ba];B[fh];W[ch];B[ef];W[cb];B[ad];W[hb];B[ed];W[bg];B[da];W[af];B[be];W[ie];B[ab];W[gi];B[bb];W[bh];B[eg];W[eb];B[hc];W[];B[ei];W[fe];B[dh];W[cg];B[ee];W[cf];B[ic];W[ha];B[bd];W[dd];B[hg];W[fc];B[he];W[hh];B[di];W[ff];B[bf];W[ii];B[gf];W[gg];B)

into
;B[df];W[ba];B[fh];W[ch];B[ef];W[cb];B[ad];W[hb];B[ed];W[bg];B[da];W[af];B[be];W[ie];B[ab];W[gi];B[bb];W[bh];B[eg];W[eb];B[hc];W[];B[ei];W[fe];B[dh];W[cg];B[ee];W[cf];B[ic];W[ha];B[bd];W[dd];B[hg];W[fc];B[he];W[hh];B[di];W[ff];B[bf];W[ii];B[gf];W[gg];)

notice on example above, remove the "B" on the last before ")"

best regards

[sgf.load] How to handle games with handicap

Hi,
I'm having a little fun coding a SGF to GIF converter.
It works pretty well for now, but I have a problem with handicap games.
When running the code:

...
game = sgf.load(name + ".sgf")
for s in game.get_default_sequence():
        move_sequence = game.get_default_sequence()[:1]
        game.play_sequence(move_sequence)
...

I get this error that pops:

File "C:\Users\olivi\Documents\SGFtoGIF\main.py", line 19, in start
    game.play_sequence(move_sequence)
sente.exceptions.IllegalMoveException: It is not currently white's turn

Am I doing something wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.