Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mprvaxa.UUCP Path: utzoo!watmath!clyde!burl!we13!ihnp4!alberta!ubc-vision!mprvaxa!tbray From: tbray@mprvaxa.UUCP (Tim Bray) Newsgroups: net.games.go Subject: encode.c, decode.c, go.h Message-ID: <449@mprvaxa.UUCP> Date: Sun, 29-Jan-84 17:48:56 EST Article-I.D.: mprvaxa.449 Posted: Sun Jan 29 17:48:56 1984 Date-Received: Sun, 5-Feb-84 12:10:50 EST Organization: Microtel Pacific Research, Burnaby BC Lines: 212 x <-- USENET insecticide = go.h ============================================================ /* magic numbers */ #define CLEAR 0 /* 2-bit encodings */ #define WHITE 1 #define BLACK 2 #define ROWS 23 /* picture dimensions */ #define COLUMNS 128 #define TOP 2 /* A1 co-ordinates */ #define LEFT 5 #define WHITECHAR 'O' /* black stone looks like this */ #define BLACKCHAR '@' /* white stone " " " */ #define CLEARCHAR '.' /* empty point " " " */ #define CLEARHANDI '+' /* handicap point " " " */ unsigned char picture[ROWS][COLUMNS] = { " A B C D E F G H I J K L M O P Q R S T", " | | | | | | | | | | | | | | | | | | |", " 1 - -", " 2 - -", " 3 - -", " 4 - -", " 5 - -", " 6 - -", " 7 - -", " 8 - -", " 9 - -", "10 - -", "11 - -", "12 - -", "13 - -", "14 - -", "15 - -", "16 - -", "17 - -", "18 - -", "19 - -", " | | | | | | | | | | | | | | | | | | |", " Captured stones: %c %d, %c %d " /*last line looks like this */ }; unsigned char rep[200],expand[362]; = end of go.h ============================================================ = encode.c =============================================================== /* encode - take a picture of a go board and produce a compressed * representation. * T. Bray, Jan. 29, 1984. This software is hereby made freely available * to everyone, who are collectively welcomed to do anything to * it that will not frighten horses in the street. */ #include#include "go.h" main() { int i,row,col,value; char *cp; for(i=0; i #include "go.h" main() { int i,row,col,value; unsigned char mark(); if (read(0, rep, 200) != 200) { fprintf(stderr, "Can't read 200 bytes of representation - exiting.\n"); exit(); } /* shuffle the compressed form into the the intermediate 'expand' array */ for(i=0; i<181; i++) { static unsigned char holder[3] = " "; holder[0] = rep[i]; /* inefficient */ sscanf(holder, "%x", &value); /* hex-to-ascii */ expand[(i * 2) + 1] = value & 3; /* get two high bits */ expand[i * 2] = value >> 2; /* two low bits */ } /* build the picture from 'expand' */ row = col = 0; for(i=0; i<361; i++) { picture[row + TOP][(col++ * 2) + LEFT] = mark(i, expand[i]); if (col == 19) { row++; col = 0; } } /* draw */ for(i = 0; i < (ROWS - 1); i++) printf("%s\n", picture[i]); rep[185] = rep[189] = 0; printf(picture[ROWS - 1], BLACKCHAR, atoi(rep + 182), WHITECHAR, atoi(rep + 186)); printf("\n"); } /* figure out what to put in a spot. Necessary for correctly showing * handicap points */ unsigned char mark(place, value) int place, value; { switch (value) { case BLACK: return(BLACKCHAR); case WHITE: return(WHITECHAR); default: /* gotta be clear */ if (place == 60 || place == 66 || place == 72 || place == 174 || place == 180 || place == 186 || place == 288 || place == 294 || place == 300) return(CLEARHANDI); else return(CLEARCHAR); } } = end of decode.h ======================================================