Does OGS provide any kind of api to return what is actually on the board

Hi, I was wondering if OGS have any api that inform the caller what positions of the board contain stones? I know appending moves returns the complete order of placing stones. However, if a stone has been taken out, it will still show up in the complete move string. What I need is a string containing only the ones that are still on the board. Is there such functionality?

Thanks

2 Likes

I can’t think off the top of my head what use-case would have made that API exist.

We have the Goban component on the client side, and it is always populated by a sequence of moves, from which it computes the state of the board.

If someone thought of a case where surely we must send the actual board position over the API, that would be a clue to go hunting :slight_smile:

1 Like

I recall a similar question being asked on the forums before, so that’s another route.

Forgive my ignorance, but didn’t you just recently add such a thing? They seem very similar to my novice eyes at least.

Curiously, the position ID does happen to consist of the position of each stone, but there are two things about it:

  1. It’s not guaranteed to consist of that, this just happens to be the implementation
  2. There isn’t a server API that supports it - the function I implemented is a call on the Goban, which gets all those stone locations the usual way from the server: by the sequence of placements.
2 Likes

Hmm the reason I want the board position and not just the move is for my project. In the electronic go board, people might accidentally touch the go piece and move them back. When they got pushed out of a certain area that opens the circuit. When people move the piece back to the middle that closes the circuit. If I don’t check what should have been on the board, the program will treat that piece as a new move, which is not ideal.

I can’t think of any more generic reasons why this api should exist though xd

2 Likes

If the on-off is happening a lot, you’ll probably want a solution that doesn’t involve the OGS API (to prevent spamming). However, review/append does provide a way to remove stones which might help: "!0"

1 Like

I modified the JavaScript code so that when multiple on-offs only happen between Arduino and itself, not between the JavaScript code and OGS. However, I could only check the last move in the move string and not more. It’s because the second last move could have been taken by the last move. It would be really great if I can know all the stones that are on the board so I can check any new move, either legit new move or the on-offs moves against what should be on the board.

2 Likes

You don’t need an ogs API call for that, just a call to a function from a go / sgf library that computes a position, given a sequence of moves. Or given a position and an extra move.

2 Likes

Cool thanks! I am looking into the sgf npm package. There aren’t that many people using it but it’s probably normal for sgf library. Did you have experience using something like this??

1 Like

In javascript, not personally, but feel free to ask questions anyway.

https://online-go.com/termination-api/game/[GAME_ID]/state

Is this what you’re looking for? Anoek answered this question awhile back in a different thread, if so: Is there a way to get the current board state of an active OGS game from the API instead of just the sequence of moves played? - #5 by anoek
It returns a few things, including an array of the board’s current state, the last move played, and an array of stones removed.

Although, to be honest, I’m not entirely sure how that second array works, since I just found this game where the last move was a capturing one: https://online-go.com/termination-api/game/48060935/state and this was the response:

json

{“move_number”:16,
“player_to_move”:388040,
“phase”:“play”,
“board”:[[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,2,2,2,0,0],
[0,0,1,0,2,0,2,0,0],
[0,0,0,1,1,2,1,0,0],
[0,0,1,0,0,2,1,0,0],
[0,0,0,0,2,0,1,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0]],
“outcome”:“”,
“removal”:[[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0]],
“last_move”:{“x”:6,“y”:3}}

Okay i actually just answered my own question, that second array is for stone removal at the end of the game, which i finally figured out by looking at one of my own finished games:
https://online-go.com/termination-api/game/47451764/state.

2 Likes

this sounds like a really cool project, I hope it goes well!! It would be awesome if you could share some pictures of it, while it’s in the works or after it’s complete :eyes:

This is great!! It’s exactly what I need. Now I just need to convert the 2d array into the move string format understood by OGS. Thanks for the reference!!

Edit: do you know if this works also with demo board?

Edit: Just confirmed that it works with review by changing “game” to “review” in the url.

3 Likes

Thanks!!! @Gooplet referred me a thread that did what I want to do. But in the future I do still want a way to play go offline. If you are don’t mind I will ask more questions when I start that part of the project.

1 Like

Thanks for the support!! I posted two videos in the other thread to share updates of the project.

GitHub and video1

Video2

I will post more updates there when I make important progress.

1 Like

Hi for some reason when I use the socket api to append moves to a demo board for the first move, this termination-api/review/[reviewID]/state api doesn’t register that first move. But when I go to the ogs website and view the demo board, the new move would appear there. Why is this happening?

Could this be another one of those data races? How much time passes between your append and the get request?

I have waited for over 5 minutes. I also tried calling the state api from postman but still got the same results.

I am not exactly sure but could it be caused by not having the refresh token set up?

The refresh token was used in Termsuji: Play Go in your terminal (if you really want to)

@lvankeulen might know about this?

1 Like

The refresh token is only used to get a new oauth access token, and you’d only need it if your access token expires. If the API doesn’t return the first move, I wouldn’t know why that is.