1 /* 2 * Copyright (c) 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Ralph Campbell. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)stoc.c 8.1 (Berkeley) 07/24/94"; 13 #endif /* not lint */ 14 15 #include "gomoku.h" 16 #include <ctype.h> 17 18 char *letters = "<ABCDEFGHJKLMNOPQRST>"; 19 20 struct mvstr { 21 int m_code; 22 char *m_text; 23 }; 24 static struct mvstr mv[] = { 25 RESIGN, "resign", 26 RESIGN, "quit", 27 SAVE, "save", 28 -1, 0 29 }; 30 31 /* 32 * Turn the spot number form of a move into the character form. 33 */ 34 char * 35 stoc(s) 36 int s; 37 { 38 static char buf[32]; 39 register int i; 40 41 for (i = 0; mv[i].m_code >= 0; i++) 42 if (s == mv[i].m_code) 43 return(mv[i].m_text); 44 sprintf(buf, "%c%d", letters[s % BSZ1], s / BSZ1); 45 return(buf); 46 } 47 48 /* 49 * Turn the character form of a move into the spot number form. 50 */ 51 ctos(mp) 52 char *mp; 53 { 54 register int i; 55 56 for (i = 0; mv[i].m_code >= 0; i++) 57 if (strcmp(mp, mv[i].m_text) == 0) 58 return(mv[i].m_code); 59 if (!isalpha(mp[0])) 60 return(ILLEGAL); 61 i = atoi(&mp[1]); 62 if (i < 1 || i > 19) 63 return(ILLEGAL); 64 return(PT(lton(mp[0]), i)); 65 } 66 67 /* 68 * Turn a letter into a number. 69 */ 70 lton(c) 71 int c; 72 { 73 register int i; 74 75 if (islower(c)) 76 c = toupper(c); 77 for (i = 1; i <= BSZ && letters[i] != c; i++) 78 ; 79 return(i); 80 } 81