Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

go_gtp

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

go_gtp

  • 0.0.4
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

The Go Text Protocol

This library wraps GNU Go's version of the Go Text Protocol or GTP. It runs GNU Go in a separate process and communicates with the program over a pipe using the GTP protocol. This makes it easy to:

  • Manage full games of Go
  • Work with SGF files
  • Analyze Go positions

Installing

This library is available as a gem, so you can install it with a command like:

gem install go_gtp

The above command may need super user privileges.

This library requires an install of GNU Go to communicate with. You will need to install that separately.

Examples

This code would load an SGF file and show the current state of the game in that file:

require "go/gtp"

go = Go::GTP.run_gnugo
go.loadsgf("game.sgf") or abort "Failed to load file"
puts go.showboard
go.quit

This shows the two main types of GTP methods. Methods like showboard() return the indicated content. In this case, you actually get back a Go::GTP::Board object which can indexed into, or just converted into a String for display as it is used here.

Other methods, like loadsgf(), are just called for their side effects and they don't return anything. For these, you get a boolean result telling you if the call succeeded (true) or triggered an error (false). You can always check the success?() of either type of call after the fact and retrieve the last_error() when there is one, so these return values are just a convenience. As another convenience, these boolean methods can be called with Ruby's query syntax as well: loadsgf?().

When working with a GNU Go process, it's a good idea to remember to call quit() so the pipe can be closed. One way to ensure that happens is to use the block form of run_gnugo() to have it done for you. Given that, the following example is another way to handle loading and displaying a game:

require "go/gtp"

Go::GTP.run_gnugo do |go|
  go.loadsgf?("game.sgf") or abort "Failed to load file"
  puts go.showboard
end  # quit called automatically after this block

You can customize how GNU Go is invoked, by passing parameters to run_gnugo(). Probably the two most useful are the :directory where the executable lives and any :arguments you would like to pass it. For example:

require "go/gtp"

go = Go::GTP.run_gnugo( directory: "/usr/local/bin",
                        arguments: "--boardsize 9" )
# ...

Of course, you could also set the board size after the connection is open with go.boardsize(9).

See the example directory for more ideas about how to use this library.

GTP Commands

The method names are literally the command names right out of the GTP documentation. That's intended to make it easy to figure out what you can do with this library. Return values are Rubified into nice objects, when it makes sense to do so.

FAQs

Package last updated on 16 Oct 2010

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc