/*
* @(#)goprova.java	1.0 00/06/25
*
*/
/**
* A java applet that calculates and prints a random go proverb.
*
* @author Steve Manson 06/25/00
* @version 5.0, 06/25/00
*/

import java.applet.*;
import java.awt.*;

public class goprova extends Applet
{
            public static String[] adjectives = {
                     "adjacent", "alive", "best", "capped", "dead", "fast", "glorious",
                     "gote", "key", "reasonable", "sente", "simplest", "simultaneous",
                     "slow", "strongest", "symmetrical", "unreasonable", "wrong"
            };
            public static String[] badthings = {
                     "amateur", "dame point", "damezumari", "dango", "death", "doubt",
                     "dumpling", "enemy", "enemy stone", "enemy's key play",
                     "empty triangle", "fancy move", "gote", "ko", "line of defeat",
                     "opponent", "plum tree", "poor player", "vulgar play", "weak group"
            };
            public static String[] goodthings = {
                     "aji", "atari", "attack", "bamboo joint",
                     "big group", "capture", "carpenter's square", "comb formation",
                     "connection", "cut", "cutting-point", "early ko", "fight",
                     "fist", "formation", "game", "hane", "influence", "joseki",
                     "key play", "knight's move", "ko", "ladder", "life", "meijin",
                     "monkey-jump", "move", "one space extension", "one stone gap",
                     "peach tree", "pincer", "play", "pon-nuki", "running battle",
                     "sabaki", "sacrifice", "sanrensai", "save", "sente",
                     "step in a ladder", "strength", "strike", "strong group",
                     "strongest stone", "stone", "symmetry", "territory", "win"
            };
            public static String[] locations = {
                     "a formation", "a ladder", "all four corners", "the bamboo joint",
                     "the center", "the corner", "the edge of the board",
                     "the enemy's territory", "the fourth line", "the head", "the inside",
                     "the second line", "the side", "the third line",
                     "the waist of the knight's move"
            };
            public static String[] values = {
                     "eight points", "everything ",
                     "four points", "nine points", "one point", "sente", "seven points",
                     "ten points", "the bamboo joint", "the cut", "the early ko",
                     "the game", "the hane", "the ko", "the one space extension",
                     "the sacrifice", "the strongest stone", "the win", "thirty points"
            };
            public static String[] verbs = {
                     "abandon", "add", "atari", "attach", "attack", "beware",
                     "capture", "count", "cut", "defend", "die", "fail", "fight",
                     "guarantee", "hane", "kill", "live", "lose", "make", "play", "remove",
                     "resign", "sabaki", "sacrifice", "save", "strike", "study",
                     "succeed", "take", "throw in", "win"
            };
            public static double rlimadj = (double)adjectives.length;
            public static double rlimbad = (double)badthings.length;
            public static double rlimgood = (double)goodthings.length;
            public static double rlimloc = (double)locations.length;
            public static double rlimval = (double)values.length;
            public static double rlimverb = (double)verbs.length;

            public static String[][] proverbs = {
                     {"v", " the ", "b", " for the ", "g", ".  "},
                     {"there is ", "b", " in the ", "g", ".  "},
                     {"a", "g", " is never ", "j", ".  "},
                     {"the ", "g", " becomes ", "g", ".  "},
                     {"the enemy's ", "j", " ", "g", " is my own ", "j", " ", "g", ".  "},
                     {"don't ", "v", " the ", "b", ".  "},
                     {"v", " at the ", "g", ".  "},
                     {"v", " at ", "l", ".  "},
                     {"never try to ", "v", " ", "a", "g", ".  "},
                     {"v", " ", "a", "g", " on ", "l", ", ", "v", " another, then ", "v", " both of them.  "},
                     {"the ", "g", " is worth ", "u", ".  "},
                     {"if you don't understand the ", "g", ", don't play go.   "},
                     {"the ", "g", " in ", "l", " is worth ", "u", " in ", "l", ".  "},
                     {"u", " in ", "l", " is worth ", "u", " in ", "l", ".  "},
                     {"when your opponent has more than one ", "b", ", ", "v", " them all at once.  "},
                     {"v", " ", "a", "g", " at the first opportunity.  "},
                     {"if you ", "v", " ", "l", ", ", "v", ".  "},
                     {"v", " to the ", "j", " ", "g", " in ", "a", "g", ".  "},
                     {"v", " the ", "g", ", ", "v", " the ", "g", ".  "},
                     {"l", ", ", "l", ", ", "l", ".  "},
                     {"l", " is the ", "b", ".  "},
                     {"g", ", ", "g", " is ", "b", ".  "},
                     {"there is ", "b", " at the ", "g", ".  "},
                     {"l", " is for ", "g", ", ", "l", " for ", "g", ".  "},
                     {"v", " more than one ", "b", " simultaneously.  "},
                     {"on ", "l", ", four ", "v", ", six ", "v", ".  "},
                     {"the ", "g", " is ", "j", ".  "},
                     {"if ", "a", "g", " is ", "j", ", ", "v", " at ", "l", ".  "},
                     {"at ", "l", " of ", "a", "g", ", ", "v", " ", "g", ".  "},
                     {"if your ", "g", " is ", "j", ", ", "v", " the ", "g", ".  "},
                     {"v", " what you cut off.  "},
                     {"g", " in ", "l", " is worth ", "a", "g", " in ", "l", ".  "},
                     {"there is no ", "g", " in ", "l", ".  "},
                     {"if you ", "v", " by ", "u", ", take a rest.  "},
                     {"each ", "g", " in ", "a", "g", " is worth ", "u", ".  "},
                     {"a", "g", " needs no ", "g", ".  "},
                     {"leave ", "a", "g", " for each ", "b", ".  "},
                     {"when you ", "v", " ", "g", ", you ", "v", " ", "u", " in strength.  "},
                     {"in ", "a", "j", " situation, ", "a", "j", " ", "g", " is ", "j", ".  "},
                     {"v", " ", "a", "g", " before striking.  "},
                     {"if you cannot ", "v", ", then ", "v", " in ", "a", "j", " fashion.  "},
                     {"only the ", "b", " tries to come up with ", "a", "b", ".  "},
                     {"v", " ", "a", "b", ", not ", "a", "g", ".  "},
                     {"the ", "j", " move is the ", "j", " move.  "},
                     {"if you ", "v", " ", "l", ", resign.  "},
                     {"a", "g", " near ", "l", " cannot be cut.  "},
                     {"when in doubt, ", "v", " the ", "b", ".  "}
            };

            public static double rlimprov = (double)proverbs.length;
            public String[] text;
            public String rtext[] = new String[20];
            public String atext[] = new String[20];
            public String captext;
            public String concat[] = new String[20];

            public void init() {
                  this.setBackground(Color.white);
            };

            public void paint(Graphics g) {
                  g.setColor(Color.black);
                  goprova t = new goprova();
                  int now = (int)(t.rlimprov*Math.random());
                  t.text = t.proverbs[now];
                  t.replace();
                  t.concat[0] = t.cap();
                  for(int k = 1; k < t.text.length; k++) t.concat[k] = t.concat [k-1] + t.atext[k];
                  g.drawString(t.concat[t.text.length - 1], 5, 15);
            };

            public String cap() {
                  String first = atext[0].substring(0, 1);
                  String capped = (first.toUpperCase() + atext[0].substring(1));
                  return capped;
            };

            public void replace(){
                  String[] vowels = {"a", "e", "i", "o", "u"};
                  String zip = " jbgluva";
                  for(int i = 0; i < text.length; i++){
                     String cur = text[i];
                     if (cur.length() > 1) rtext[i] = cur;
                     else if (cur.charAt(0) == zip.charAt(0)) rtext[i] = " ";
                     else if (cur.charAt(0) == zip.charAt(1)) rtext[i] = adjectives[(int)(rlimadj*Math.random())];
                     else if (cur.charAt(0) == zip.charAt(2)) rtext[i] = badthings[(int)(rlimbad*Math.random())];
                     else if (cur.charAt(0) == zip.charAt(3)) rtext[i] = goodthings[(int)(rlimgood*Math.random())];
                     else if (cur.charAt(0) == zip.charAt(4)) rtext[i] = locations[(int)(rlimloc*Math.random())];
                     else if (cur.charAt(0) == zip.charAt(5)) rtext[i] = values[(int)(rlimval*Math.random())];
                     else if (cur.charAt(0) == zip.charAt(6)) rtext[i] = verbs[(int)(rlimverb*Math.random())];
                     else if (cur.charAt(0) == zip.charAt(7)) rtext[i] = "a";
                  };
                  for(int i = 0; i < text.length; i++){
                     String cur = rtext[i];
                     if (cur.length() > 1) atext[i] = cur;
                     else if (cur.charAt(0) == zip.charAt(0)) atext[i] = " ";
                     else if (cur.charAt(0) == zip.charAt(7)) {
                          String plusone = rtext[i+1];
                          String first = plusone.substring(0, 1);
                          boolean test = false;
                          for(int j = 0; j < 5; j++){
                             String comp = vowels[j];
                             if (first.charAt(0) == comp.charAt(0)) test = true;
                          };
                          if (test) atext[i] = "an ";
                          else atext[i] = "a ";
                     };
                  };
            return;
            };
}


