Life In 19x19
http://www.lifein19x19.com/

Quick tool to convert EidoGo to [go] diagram
http://www.lifein19x19.com/viewtopic.php?f=18&t=10030
Page 1 of 1

Author:  oca [ Wed Mar 19, 2014 7:36 am ]
Post subject:  Quick tool to convert EidoGo to [go] diagram

Hello,

Just wanted to share with you a quick tool I did to convert an EidoGo board to a [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.

Image

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


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 :
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());
   }
}


Author:  DrStraw [ Wed Mar 19, 2014 9:10 am ]
Post subject:  Re: Quick tool to convert EidoGo to [go] diagram

Well, very nice. But I cannot quite see why the go format would be preferred over the eidogo format.

Author:  RBerenguel [ Wed Mar 19, 2014 10:50 am ]
Post subject:  Re: Quick tool to convert EidoGo to [go] diagram

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.

Author:  oca [ Wed Mar 19, 2014 11:37 pm ]
Post subject:  Re: Quick tool to convert EidoGo to [go] diagram

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 [go] tag.

Author:  DrStraw [ Thu Mar 20, 2014 6:00 am ]
Post subject:  Re: Quick tool to convert EidoGo to [go] diagram

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.

Page 1 of 1 All times are UTC - 8 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/