Quick tool to convert EidoGo to [go] diagram

For discussing go computing, software announcements, etc.
Post Reply
User avatar
oca
Lives in gote
Posts: 699
Joined: Wed Feb 19, 2014 2:53 am
Rank: DDK
GD Posts: 0
KGS: aco
IGS: oca
OGS: oca
Location: Switzerland
Has thanked: 485 times
Been thanked: 166 times

Quick tool to convert EidoGo to [go] diagram

Post by oca »

Hello,

Just wanted to share with you a quick tool I did to convert an EidoGo board to a
Click Here To Show Diagram Code
[go] "text" diagram

The tool is a java application that you start and that will do a copy of the screen and then processes the image to find the goban and render it as text.

Once that done, the "text" is placed into the clipboard ready to be paste where you want, and finally a dialog
is shown to show what as been found.

here is a screenshoot.

[img]http://picshell.ovh.org/go/diagToTxt.jpg[/img]

To use it, you need java to be on your computer, and you need to download the program "DiagToTxt.jar"
(jar stands for Java ARchive).

The file is available here :
http://picshell.ovh.org/go

and download "diagtotxt.jar"

to execute the programme, you need to type the following command (or put it in a .bat file which must be in the smae folder as diagtotxt.jar)

[code]
start javaw -cp diagtotxt.jar oca.DiagToTxt
[/code]

It's really important to start it that way so that no java console is displayed (if the console is displayed,
it may comes in front of the Eidigo diagram and the console will be present in the image...)

Limitation : only work with 19x19 boards.

Enyoy.

for whose who want to see the java code :
[hide][code]package oca;

import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.plaf.FontUIResource;

public class DiagToTxt {
public static void main(String[] args) throws Exception {

BufferedImage image;

Robot robot = new Robot();
image = robot.createScreenCapture(new Rectangle(Toolkit
.getDefaultToolkit().getScreenSize()));
// String format ="PNG" ;
// ImageIO.write(image, format, new File("screenShot."+format));
// image = ImageIO.read(new File("screenShot."+format));

int startPosY = -1;
int startPosX = -1;
/*
* Find starting point
*/
for (int y = 0; y < image.getHeight(); y++) {
StringBuffer line = new StringBuffer();
for (int x = 0; x < image.getWidth(); x++) {
int clr = image.getRGB(x, y);
if (clr == -2245525) { // = background color "DDBC6B"
line.append("_");
} else {
line.append("X");
}
}
int tmp = line
.toString()
.indexOf(
"___________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________");
if (tmp > -1) {
startPosY = y;
startPosX = tmp;
break;
}
}
int margin = 14;
int nbPixPerSquare = 19;
int py = 0;

StringBuffer goban = new StringBuffer();
goban.append("[go]$$\n");
goban.append("$$ ----------------------------------------\n");

for (int y = startPosY + margin; y < (startPosY + margin + 18
* nbPixPerSquare + 1); y += nbPixPerSquare) {
py++;
goban.append("$$ | ");
for (int x = startPosX + margin; x < (startPosX + margin + 18
* nbPixPerSquare + 1); x += nbPixPerSquare) {
int clr = image.getRGB(x, y - 6);
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;
String r = String.format("%02X%02X%02X", red, green, blue);
int clrCenter = image.getRGB(x, y );

String car = ".";
if (clrCenter==-9412810) {
car = ",";
} else if (r.equals("383838")) {
car = "X";
} else if (r.equals("FEFEFE")) {
car = "O";
}
goban.append(car + " ");
}
goban.append("|\n");
}
goban.append("$$ ----------------------------------------[/go]
\n");

StringSelection selection = new StringSelection(goban.toString());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
javax.swing.UIManager.put("OptionPane.messageFont", new FontUIResource(
new Font("Courier", Font.PLAIN, 12)));
JOptionPane.showMessageDialog(null,
"DiagToTxt 1.0 by oca\nClipboard content :\n" + goban.toString());
}
}

[/code][/hide]
Converting the book Shape UP! by Charles Matthews/Seong-June Kim
to the gobook format. last updated april 2015 - Index of shapes, p.211 / 216
DrStraw
Oza
Posts: 2180
Joined: Tue Apr 27, 2010 4:09 am
Rank: AGA 5d
GD Posts: 4312
Online playing schedule: Every tenth February 29th from 20:00-20:01 (if time permits)
Location: ʍoquıɐɹ ǝɥʇ ɹǝʌo 'ǝɹǝɥʍǝɯos
Has thanked: 237 times
Been thanked: 662 times
Contact:

Re: Quick tool to convert EidoGo to [go] diagram

Post by DrStraw »

Well, very nice. But I cannot quite see why the go format would be preferred over the eidogo format.
Still officially AGA 5d but I play so irregularly these days that I am probably only 3d or 4d over the board (but hopefully still 5d in terms of knowledge, theory and the ability to contribute).
User avatar
RBerenguel
Gosei
Posts: 1585
Joined: Fri Nov 18, 2011 11:44 am
Rank: KGS 5k
GD Posts: 0
KGS: RBerenguel
Tygem: rberenguel
Wbaduk: JohnKeats
Kaya handle: RBerenguel
Online playing schedule: KGS on Saturday I use to be online, but I can be if needed from 20-23 GMT+1
Location: Barcelona, Spain (GMT+1)
Has thanked: 576 times
Been thanked: 298 times
Contact:

Re: Quick tool to convert EidoGo to [go] diagram

Post by RBerenguel »

DrStraw wrote:Well, very nice. But I cannot quite see why the go format would be preferred over the eidogo format.
For pasting specific positions or areas here, in this same forum or in Sensei's library. For example.
Geek of all trades, master of none: the motto for my blog mostlymaths.net
User avatar
oca
Lives in gote
Posts: 699
Joined: Wed Feb 19, 2014 2:53 am
Rank: DDK
GD Posts: 0
KGS: aco
IGS: oca
OGS: oca
Location: Switzerland
Has thanked: 485 times
Been thanked: 166 times

Re: Quick tool to convert EidoGo to [go] diagram

Post by oca »

DrStraw wrote:Well, very nice. But I cannot quite see why the go format would be preferred over the eidogo format.
Yes, you right, there is not that much usage for it... so I don't excpect it to win the "2014 Most downloaded go program award" :D
I still missed that kind of tool in a few occasions,for taking a "snapshoot" of the game to talk about a specific position. For that purpose, I prefer the
Click Here To Show Diagram Code
[go] tag.[/go]
Converting the book Shape UP! by Charles Matthews/Seong-June Kim
to the gobook format. last updated april 2015 - Index of shapes, p.211 / 216
DrStraw
Oza
Posts: 2180
Joined: Tue Apr 27, 2010 4:09 am
Rank: AGA 5d
GD Posts: 4312
Online playing schedule: Every tenth February 29th from 20:00-20:01 (if time permits)
Location: ʍoquıɐɹ ǝɥʇ ɹǝʌo 'ǝɹǝɥʍǝɯos
Has thanked: 237 times
Been thanked: 662 times
Contact:

Re: Quick tool to convert EidoGo to [go] diagram

Post by DrStraw »

RBerenguel wrote:
DrStraw wrote:Well, very nice. But I cannot quite see why the go format would be preferred over the eidogo format.
For pasting specific positions or areas here, in this same forum or in Sensei's library. For example.
oh, yeah. I tend to forget about SL.
Still officially AGA 5d but I play so irregularly these days that I am probably only 3d or 4d over the board (but hopefully still 5d in terms of knowledge, theory and the ability to contribute).
Post Reply