/* Scrabble : An interactive scrabble playing software. Copyright (C) 1999 Amitabh Sinha All Trademarks and Copyrights pertaining to Scrabble, Java, Linux acknowledged. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact Amitabh at */ import java.io.*; import java.util.*; public class ComputerPlayer extends Player { int timeLimit; ScrabbleBoard board; int skips; boolean show; boolean blankUsed; public ComputerPlayer (String s, int t, ScrabbleBoard b, LetterBag l) { name = s; letters = new Vector(); timeLimit = t; board = b; letterBag = l; for (int i=0; i<7; i++) { Letter ll = letterBag.getLetter(); if (ll.getLetter()==' ') ll.setValue('E'); letters.addElement(ll); } } public void setShow(boolean s) { show = s; } public String getSLetters() { String s = new String(); for (int i=0; i0 && i<14 && !board.cellAt(i-1,j).isOccupied() && !board.cellAt(i+1,j).isOccupied()) || (i==14 && !board.cellAt(i-1,j).isOccupied())) dir = 'y'; else if ((j==0 && !board.cellAt(i,j+1).isOccupied()) || (j>0 && j<14 && !board.cellAt(i,j-1).isOccupied() && !board.cellAt(i,j+1).isOccupied()) || (j==14 && !board.cellAt(i,j-1).isOccupied())) dir = 'x'; else continue; char cc = board.cellAt(i,j).getLetter().getLetter(); int idx = -1; while ((idx = missings.indexOf(new Character(cc), idx+1)) != -1) { if (dir == 'y') { String tryWord = ((String) almosts.elementAt(idx)); Character misChar = (Character) missings.elementAt(idx); int yy = j; int xx = i - tryWord.indexOf(misChar.charValue()); if (xx<0) break; if (board.computerValid(tryWord, misChar.charValue(), xx, yy, dir)) { int pts = board.computePoints(tryWord, xx, yy, dir, false); if (pts > points-10) pts += board.computePotential(tryWord, xx, yy, dir); if (((Boolean)almostBlanks.elementAt(idx)).booleanValue() == true) pts -= 8; if (pts > points) { points = pts; finalWord = tryWord; word = new Vector(); for (int ii=0; ii points-10) pts += board.computePotential(tryWord, xx, yy, dir); if (pts > points) { points = pts; finalWord = tryWord; word = new Vector(); for (int ii=0; ii points-10) pts += board.computePotential(tryWord, i, j, 'x'); if (pts > points) { points = pts; finalWord = tryWord; fuller = true; word = new Vector(); for (int ii=0; ii points-4) pts += board.computePotential(tryWord, i, j, 'y'); if (pts > points) { points = pts; finalWord = tryWord; fuller = true; word = new Vector(); for (int ii=0; ii=7) { for (int i=0; i<7; i++) letters.addElement(letterBag.getLetter()); for (int i=0; i<7; i++) { letterBag.returnLetter((Letter)letters.elementAt(0)); letters.removeElement(letters.elementAt(0)); } Dialog dd = new Dialog ("Moistone has changed letters. Your turn."); return true; } else { Vector sword = new Vector(); for (Enumeration e=word.elements(); e.hasMoreElements();) { Character ccc = (Character) e.nextElement(); int j; boolean added = false; for (j=0; j7) return false; for (int i=0; i8) return '0'; for (int i=0; i