jabble/ 40755 2743 34 0 6336535214 10506 5 ustar gary pgrad jabble/Sock.java 100644 2743 34 3243 6336306455 12352 0 ustar gary pgrad import java.util.Random;
class Sock extends Letters {
static Random rand = new Random();
/** Score for each letter **/
public static byte value[] =
// a b c d e f g h i j k l m n o p q r s t u v w x y z #
{0,1,3,3,2,1, 4,2,4,1,8, 5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10,0,
// scores for blank posing as each letter
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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
static int start_quantity[] =
// a b c d e f g h i j k l m n o p q r s t u v w x y z # */
{0,9,2,2,4,12,2,3,2,9,1,1,4,2,6,8,2, 1,6,4,6,4,2,2,1,2, 1,2};
Sock () {
super();
reset();
}
/** Reset for a new game **/
void
reset() {
System.arraycopy( start_quantity, 0, letter, 0, letter.length );
}
/** Pick a random letter from the sock **/
int
pick() {
int n = count(); // how many letters left
if (n==0)
throw new Error("pick from empty sock");
// random number between 1 and n
int r = (Math.abs(rand.nextInt()) % n) + 1;
for (int j=1; j< letter.length; j++) {
if (r <= letter[j]){
letter[j]--;
return j;
} else {
r -= letter[j];
}
}
throw new Error("n: "+n+" r: "+r);
}
/** Replace the (possibly null) list of letters back into the sock **/
void
replace(int[] letters) {
// todo
}
/** Return the total score for the letters in 'a' **/
static int
score(int[]a) {
int total = 0;
for(int j=0; j< a.length; j++)
total += value[a[j]&CHAR];
return total;
}
}
jabble/Assert.java 100644 2743 34 141 6301716031 12651 0 ustar gary pgrad class Assert {
public static void
assert(boolean e) {
if(!e) throw new Error("assert");
}
}
jabble/README 100644 2743 34 120 6336533466 11443 0 ustar gary pgrad Requires JDK1.1 or better
in the jabble directory,
javac *.java
java Jabble
jabble/doit 100755 2743 34 74 6336533155 11433 0 ustar gary pgrad #!/plan9/bin/rc
javac -g -depend Jabble.java && java Jabble
jabble/jcrab.prj 100644 2743 34 14500 6336533634 12425 0 ustar gary pgrad ;; -*- Lisp -*-
(Created-By-Prcs-Version 1 2 0)
(Project-Description "")
(Project-Version jcrab 0 36)
(Parent-Version jcrab 0 35)
(Version-Log "")
(New-Version-Log "")
(Checkin-Time "Thu, 15 May 1997 17:13:32 +1000")
(Checkin-Login gary)
(Populate-Ignore ())
(Project-Keywords)
(Files
;; This is a comment. Fill in files here.
;; For example: (prcs/checkout.cc ())
;; Files added by populate at Wed, 26 Feb 1997 00:49:55 -1300:
(DawgConst.java (jcrab/0_DawgConst. 1.1.4.2 644))
(DragArea.java (jcrab/4_DragArea.j 1.5.1.16 644))
(Rack.java (jcrab/6_Rack.java 1.5 644))
(Move.java (jcrab/12_Move.java 1.7.4.5 644))
(Letters.java (jcrab/13_Letters.ja 1.2 644))
(Dawg.java (jcrab/16_Dawg.java 1.6 644))
(Makefile (jcrab/17_Makefile 1.1 644))
(Board.java (jcrab/18_Board.java 1.10 644))
(Mask.java (jcrab/21_Mask.java 1.4 644))
(Assert.java (jcrab/24_Assert.jav 1.1 644))
(Sock.java (jcrab/25_Sock.java 1.3 644))
;; Files added by populate at Sat, 19 Apr 1997 22:11:21 +1000:
(TestFrame.java (jcrab/b/50_TestFrame. 1.3 644))
;; Files deleted by populate at Sat, 19 Apr 1997 22:11:21 +1000:
; BoardUI.java
;; Files deleted by populate at Sat, 19 Apr 1997 22:21:40 +1000:
; oldjcrab/RCS/CHANGELOG
; oldjcrab/RCS/_
; oldjcrab/RCS/EdgeList.java,v
; oldjcrab/RCS/eval.java,v
; oldjcrab/RCS/genmove.java,v
; oldjcrab/RCS/globals.java,v
; oldjcrab/RCS/graphics.java,v
; oldjcrab/RCS/Checks.java,v
; oldjcrab/RCS/manager.java,v
; oldjcrab/RCS/trie.java,v
; oldjcrab/RCS/WordList.java,v
; oldjcrab/RCS/command.java,v
; oldjcrab/RCS/Board.java,v
; oldjcrab/RCS/Dawg.java,v
; oldjcrab/RCS/Assert.java,v
; oldjcrab/RCS/Crab.java,v
; oldjcrab/RCS/Makefile,v
; oldjcrab/RCS/A.java,v
; oldjcrab/RCS/Sock.java,v
; oldjcrab/RCS/Move.java,v
; oldjcrab/RCS/Game.java,v
; oldjcrab/RCS/LetterCollection.java,v
; oldjcrab/RCS/Rack.java,v
; oldjcrab/RCS/Scrabble.java,v
; oldjcrab/RCS/Anchor.java,v
; oldjcrab/RCS/Mask.java,v
; oldjcrab/RCS/Player.java,v
; oldjcrab/RCS/Letters.java,v
; oldjcrab/RCS/RobotPlayer.java,v
; oldjcrab/RCS/Array.java,v
; oldjcrab/RCS/BoardConst.java,v
; oldjcrab/RCS/VRPlayer.java,v
; oldjcrab/RCS/Genmove.java,v
; oldjcrab/RCS/UI.java,v
; oldjcrab/RCS/DragArea.java,v
; oldjcrab/RCS/Tile.java,v
; oldjcrab/RCS/VHPlayer.java,v
; oldjcrab/RCS/UIPlayer.java,v
; oldjcrab/RCS/RUIPlayer.java,v
; oldjcrab/RCS/Node.java,v
; oldjcrab/RCS/CompDict.java,v
; oldjcrab/RCS/HUIPlayer.java,v
; oldjcrab/RCS/Const.java,v
; oldjcrab/RCS/Scrapplet.java,v
;; Files added by populate at Sun, 20 Apr 1997 20:19:49 +1000:
(WordList.java (jcrab/b/0_WordList.java 1.3 644))
(CompDict.java (jcrab/c/0_CompDict.java 1.2.4.1 644))
;; Files deleted by populate at Sun, 20 Apr 1997 20:19:49 +1000:
; jdict/Makefile
; jdict/compdict.c
; jdict/dawg.h
; jdict/vgrab.c
; DragArea.class
; Tile.class
; BoardToPixel.class
; TestFrame.class
; Assert.class
; oldjcrab/dict/CompDict.java
; oldjcrab/dict/WordList.java
; oldjcrab/old/trie.java
; oldjcrab/old/globals.java
; oldjcrab/old/graphics.java
; oldjcrab/old/manager.java
; oldjcrab/old/genmove.java
; oldjcrab/old/command.java
; oldjcrab/old/checks.java
; oldjcrab/old/eval.java
; oldjcrab/old/WordList.java
; oldjcrab/old/HUIPlayer.java
; oldjcrab/old/RUIPlayer.java
; oldjcrab/old/UIPlayer.java
; oldjcrab/old/Player.java
; oldjcrab/old/RobotPlayer.java
; oldjcrab/old/Genmove.java
; oldjcrab/BoardUI.java
; images
; BoardToPixel.java
; Player.java
; RobotPlayer.java
; HUIPlayer.java
; Game.java
; UI.java
; RUIPlayer.java
; UIPlayer.java
; Scrapplet.java
;; Files added by populate at Sun, 20 Apr 1997 23:07:35 +1000:
;; Files deleted by populate at Sun, 20 Apr 1997 23:07:35 +1000:
; NOTES
;; Files added by populate at Mon, 21 Apr 1997 08:10:10 -1400:
;; Files deleted by populate at Mon, 21 Apr 1997 08:10:38 -1400:
; WordList.class
; Jcrab.class
; Dawg.class
; Tile.class
; DawgConst.class
; DragArea.class
; Assert.class
; Move.class
; TestFrame.class
; DictNode.class
; BadMove.class
; BadMoveException.class
; CompDict.class
;; Files added by populate at Mon, 21 Apr 1997 17:09:16 +1000:
;; Files deleted by populate at Mon, 21 Apr 1997 17:09:16 +1000:
; BadMoveException.java
;; Files deleted by populate at Mon, 21 Apr 1997 17:09:51 +1000:
; Gap.class
; Sock.class
; DawgConst.class
; BadMoveException.class
; WordList.class
; Assert.class
; Dawg.class
; Mask.class
; Tile.class
; Rack.class
; Array.class
; Move.class
; Letters.class
; Genmove.class
; DragArea.class
; TestFrame.class
; TODO
; ospd.trie
;; Files removed by depopulate at Mon, 21 Apr 1997 17:36:39 +1000:
; Tile.java
;; Files added by populate at Mon, 21 Apr 1997 21:33:48 +1000:
(Tile.java (jcrab/32_Tile.java 1.7 644))
;; Files removed by depopulate at Mon, 21 Apr 1997 21:51:59 +1000:
; 00Manifest
;; Files added by populate at Mon, 21 Apr 1997 21:52:23 +1000:
;; Files added by populate at Mon, 12 May 1997 19:34:37 +1000:
(00Manifest (jcrab/34_00Manifest 1.3 644))
;; Files added by populate at Mon, 12 May 1997 20:40:19 +1000:
(Row.java (jcrab/35_Row.java 1.5 644))
;; Files added by populate at Wed, 14 May 1997 16:35:27 +1000:
(ospd.trie (jcrab/36_ospd.trie 1.1 644) :no-keywords)
;; Files deleted by populate at Wed, 14 May 1997 16:35:27 +1000:
; Manifest
; jcrab.pkg
; tmp.java
; Jcrab.java
; doit
; Genmove.java
; DragArea.txt
; Array.java
;; Files added by populate at Thu, 15 May 1997 11:12:38 +1000:
(Demo.java (jcrab/37_Demo.java 1.1 644))
;; Files added by populate at Thu, 15 May 1997 17:00:42 +1000:
(Problem.java (jcrab/39_Problem.ja 1.1 644))
(DragTile.java (jcrab/40_DragTile.j 1.1 644))
;; Files added by populate at Thu, 15 May 1997 17:07:54 +1000:
(Jabble.java (jcrab/41_Jabble.jav 1.2 644))
;; Files deleted by populate at Thu, 15 May 1997 17:09:14 +1000:
; Scrabble.java
)
(Merge-Parents)
(New-Merge-Parents)
jabble/Mask.java 100644 2743 34 377 6336314571 12331 0 ustar gary pgrad class Mask {
int col;
int score;
int mask;
Mask (int col, int score, int mask){
this.col = col;
this.score = score;
this.mask = mask;
}
public String toString() {
return "Mask: " + col + "," + score + "," + Dawg.maskToString(mask);
}
}
jabble/CompDict.java 100644 2743 34 11327 6326650031 13166 0 ustar gary pgrad import java.io.*;
import java.util.*;
/**
compdict - a program to construct a dictionary trie for scrabble
Use:
time java -mx15m CompDict ~/pkg/ospd ospd.trie
(-mx15m -> allocate 15 MB to the heap)
creates the file ospd.trie. The root is the very last element.
Statistics about nodes and edges in the dawg are reported on
standard output.
(real 27.8
user 15.6
sys 5.7
)
See the file dawg.h for the format of the dawg data structure.
The wordlist MUST be in the form ([a-z]*\n)* and in strictly
increasing lexicographic order, or compdict will weird out.
**/
class CompDict implements DawgConst {
public static char[] buffer;
public static char[] newbuffer;
public static int string =0;
// accounting
public static long nodesused = 1;
public static long edgesused = 1;
public static long nodessaved = 0;
public static long edgessaved = 0;
public static BufferedReader indata;
public static DataOutputStream outdata;
public static long inlength;
public static Hashtable table;
public static void
main(String [] av) throws FileNotFoundException, IOException{
// input file
File infile = new File(av[0]);
indata = new BufferedReader(new FileReader(infile));
inlength= infile.length();
// hash table
table = new Hashtable((int)inlength, (float)0.25);
// output
outdata = new DataOutputStream(new FileOutputStream(new File(av[1])));
// make sure buffer has enough space
buffer = "**************************************".toCharArray();
convert();
}
/** Convert from 'indata' to 'outdata' **/
public static void
convert() throws IOException{
nextword(); // get first word
outdata.writeInt(0); // dummy
int root = makenode (0);
outdata.writeInt(root);
System.err.println (
nodesused + "+" + nodessaved + " nodes;" +
edgesused + "+" + edgessaved + " edges" +
root + "+" + "root");
}
/**
Makenode takes a prefix (as postion relative to stringbuf) and
returns an index of the start node of a dawg that recognizes all
words beginning with that prefix. String is a pointer (relative
to stringbuf) indicating how much of prefix is matched in the
input.
**/
public static int
makenode(int prefix) throws IOException{
int edge;
int[] edges = new int[26];
int nedges = 0;
while (prefix == string) { // More edges out of node */
// advance one character
edge = buffer[string] = newbuffer[string];
string++;
edge -= 'a' -1;
edge &= CHAR;
if(string == newbuffer.length) { // end of a word
edge |= WORD;
nextword();
}
if(!(string<0))
edge |= makenode(prefix+1);
edges[nedges++] = edge;
}
return storenode(edges, nedges);
}
/** Store the next word in 'newbuffer', adjust 'string' **/
public static void
nextword() throws IOException{
String s = indata.readLine();
if (s==null){
string = -1;
return ;
}
newbuffer = s.toCharArray();
buffer[newbuffer.length] = '*';
string = 0;
while(buffer[string] == newbuffer[string])
string++;
return ;
}
public static int
storenode(int[] edges, int numedges) throws IOException{
DictNode n;
if (numedges == 0)
return 0; /* Special node zero - no edges */
edges[numedges-1] |= LAST; /* Mark the last edge */
n = hash (edges, numedges); /* Look up node in hash table */
if (n.index != 0) { // same as an existing node
edgessaved += numedges;
nodessaved++;
} else { // a new node
n.index = (int)edgesused; // index into table
edgesused += numedges;
nodesused++;
outedges(edges, numedges);
}
return (n.index << INDEX);
}
public static void
outedges(int[] e, int n) throws IOException{
for( int j=0; j> 1) ^ e[i];
return key;
}
public boolean equals(Object o) {
DictNode other = (DictNode) o;
if(other.n != n)
return false;
for(int j=0; j