
import java.awt.* ; 
import java.applet.Applet ; 
import java.applet.AppletContext ; 
import java.net.URL ; 
import java.net.MalformedURLException ; 
import java.lang.String ; 

public class Jothello extends Applet { 

BOARD Board ; 
COMP Comp ; 
Panel control ; 
Choice Level ; 
MESSAGE Message ; 

int board[][] = new int[8 ][8 ] ; 
int color = 1 ; 
final int black = 1 ; 
final int white = - 1 ; 
final int blank = 0 ; 
int black_num = 2 ; 
int white_num = 2 ; 
int level = 0 ; 
int level_up = 9 ; 
int level_swap = 0 ; 

int undo_color[] = new int[60 ] ; 
int undo_column[] = new int[60 ] ; 
int undo_row[] = new int[60 ] ; 
int tricks = 0 ; 

GridBagLayout gridbag ; 
GridBagConstraints bagConstr ; 

boolean registering = false ; 
boolean registeringe = false ; 

public void init() { testworks.runtime.jrun.SegHit(0, 1);

String last_spart = getParameter("last_spart") ; 

if (testworks.runtime.jrun.ExpHit(0, 2, last_spart != null) ){ 
level_up = Integer.parseInt(last_spart) ; 
} 

String regist = getParameter("regist") ; 

if (testworks.runtime.jrun.ExpHit(0, 4, regist != null) ){ 
registering = true ; 
} 

String registe = getParameter("registe") ; 

if (testworks.runtime.jrun.ExpHit(0, 6, registe != null) ){ 
registeringe = true ; 
} 


System.out.println("") ; 
System.out.println("") ; 
System.out.println("") ; 
System.out.println("") ; 
System.out.println("") ; 
System.out.println("") ; 
System.out.println("") ; 
System.out.println("") ; 
System.out.println("                  Jothello 3.1 modified 6") ; 
System.out.println("") ; 
System.out.println("                     for Java browser") ; 
System.out.println("") ; 
System.out.println("                        Nov/10/1996") ; 
System.out.println("") ; 
System.out.println("             CopyRight (C) Tadasuke Yamaguchi  ") ; 
System.out.println("") ; 
System.out.println("                    All Rights Reserved.") ; 
System.out.println("") ; 
System.out.println(" Jothello is an interactive program written in Java for playing") ; 
System.out.println(" othello game. It runs on some Java browsers. And this is free") ; 
System.out.println(" software. So, permission is granted to make copies of this program.") ; 
System.out.println("") ; 
System.out.println(" Please send me report of bugs you may meet on Jothello by email.") ; 
System.out.println(" E-mail to sph40086@@bkc.ritsumei.ac.jp or echizen@@mbox2.inet-osaka.or.jp") ; 
System.out.println(" Of cource, your sugestions are welcome, too.") ; 
System.out.println("") ; 
System.out.println(" Jothello's Home URL ") ; 
System.out.println(" http://www.ritsumei.ac.jp/bkc/~sph40086/java/Jothello/index-j.html") ; 
System.out.println("") ; 
System.out.println(" Java is a registered trademark of Sun Microsystems, Inc. .") ; 
System.out.println("") ; 
System.out.println("") ; 
System.out.println("") ; 
System.out.println("") ; 
System.out.println("") ; 
System.out.println("") ; 
System.out.println("") ; 


Get_new() ; 

Layout_init() ; 

Data_init() ; 

Draw_init() ; 
} 

public void Get_new() { testworks.runtime.jrun.SegHit(1, 1);

control = new Panel() ; 

Comp = new COMP(this) ; 

Board = new BOARD(this) ; 

Level = new Choice() ; 

Message = new MESSAGE(this) ; 

COMP_DATA data = new COMP_DATA() ; 
} 

public void Layout_init() { testworks.runtime.jrun.SegHit(2, 1);

gridbag = new GridBagLayout() ; 
bagConstr = new GridBagConstraints() ; 

setLayout(gridbag) ; 
bagConstr.gridx = 0 ; 
bagConstr.gridy = 0 ; 
bagConstr.ipadx = Board.width ; 
bagConstr.ipady = Board.height ; 
gridbag.setConstraints(Board , bagConstr) ; 
add(Board) ; 

bagConstr.gridy = 1 ; 
bagConstr.ipadx = Board.width ; 
bagConstr.ipady = Board.line_terval + 1 ; 
gridbag.setConstraints(Message , bagConstr) ; 
add(Message) ; 

bagConstr.gridy = 2 ; 
bagConstr.ipadx = 0 ; 
bagConstr.ipady = 0 ; 
gridbag.setConstraints(control , bagConstr) ; 
add(control) ; 

control.add(new Button("Undo")) ; 
control.add(new Button("Pass")) ; 
control.add(new Button("Reset")) ; 

Level.addItem("very easy") ; 
Level.addItem("easy") ; 
Level.addItem("normal") ; 
Level.addItem("difficult") ; 

Level.setBackground(Color.lightGray) ; 
control.add(Level) ; 
} 

public void Data_init() { testworks.runtime.jrun.SegHit(3, 1);

for (int column = 0 ; testworks.runtime.jrun.ExpHit(3, 2, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(3, 4, row< 8 ); row++) { 
board[column ][row ] = blank ; 
} 
} 
board[3 ][3 ] = board[4 ][4 ] = white ; 
board[3 ][4 ] = board[4 ][3 ] = black ; 
} 

public void Draw_init() { testworks.runtime.jrun.SegHit(4, 1);

Message.init() ; 

Message.WriteCount() ; 
Message.WriteTurn() ; 
Message.repaint() ; 

Board.init() ; 

Board.draw_board() ; 
Board.draw_all_pieces() ; 
} 

public boolean action(Event evt , Object arg) { testworks.runtime.jrun.SegHit(5, 1);

if (testworks.runtime.jrun.ExpHit(5, 2, Board.turnning) ){ 
return false ; 
} 

if (testworks.runtime.jrun.ExpHit(5, 4, evt.target instanceof Button)) { 

if (testworks.runtime.jrun.ExpHit(5, 6, "Undo".equals(arg)) ){ 
Undo() ; 
} 

if (testworks.runtime.jrun.ExpHit(5, 8, "Pass".equals(arg)) ){ 
Pass() ; 
} 

if (testworks.runtime.jrun.ExpHit(5, 10, "Reset".equals(arg)) ){ 
Reset() ; 
} 
} 
else if (testworks.runtime.jrun.ExpHit(5, 12, evt.target instanceof Choice)) { 
String choice =(String) arg ; 

if (testworks.runtime.jrun.ExpHit(5, 14, choice.equals("very easy")) ){ 
level = 0 ; 
level_swap = level ; 
} 
else if (testworks.runtime.jrun.ExpHit(5, 16, choice.equals("easy")) ){ 
level = 1 ; 
level_swap = level ; 
} 
else if (testworks.runtime.jrun.ExpHit(5, 18, choice.equals("normal")) ){ 
level = 2 ; 
level_swap = level ; 
} 
else if (testworks.runtime.jrun.ExpHit(5, 20, choice.equals("difficult")) ){ 
level = 3 ; 
level_swap = level ; 
} 

if (testworks.runtime.jrun.ExpHit(5, 22, black_num + white_num > 64 - level_up) ){ 
level = 64 -(black_num + white_num) ; 
} 
else if (testworks.runtime.jrun.ExpHit(5, 24, black_num + white_num + 3 >= 64 - level_up) ){ 
level = level_swap + 3 ; 
} 

} 
return true ; 
} 

public boolean Undo() { testworks.runtime.jrun.SegHit(6, 1);

if (testworks.runtime.jrun.ExpHit(6, 2, tricks == 0) ){ 
return false ; 
} 

BREAK_POINT : 
for (int num = tricks - 1 ; testworks.runtime.jrun.ExpHit(6, 4, num>= 0 ); num--) { 
if (testworks.runtime.jrun.ExpHit(6, 6, undo_color[num ] == color) ){ 
tricks = num ; 
break BREAK_POINT ; 
} 
} 

Data_init() ; 

for (int num = 0 ; testworks.runtime.jrun.ExpHit(6, 8, num< tricks ); num++) { 
turn_up(board , undo_column[num ] , undo_row[num ] , undo_color[num ]) ; 
} 

Board.draw_board() ; 

Board.draw_all_pieces() ; 

Board.repaint() ; 

Message.WriteCount() ; 

Message.WriteTurn() ; 

Message.repaint() ; 

if (testworks.runtime.jrun.ExpHit(6, 10, black_num + white_num <= 64 - level_up) ){ 
level = level_swap ; 
} 
if (testworks.runtime.jrun.ExpHit(6, 12, black_num + white_num + 3 > 64 - level_up) ){ 
level = level_swap + 3 ; 
} 

return true ; 
} 

public void Pass() { testworks.runtime.jrun.SegHit(7, 1);

if (testworks.runtime.jrun.ExpHit(7, 2, (black_num + white_num) != 4) ){ 
for (int column = 0 ; testworks.runtime.jrun.ExpHit(7, 4, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(7, 6, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(7, 8, Comp.possible(board , column , row , - 1 * Comp.comp_color)) ){ 
return ; 
} 
} 
} 
color = Comp.comp_color ; 
} 
else { 
Comp.comp_color = color ; 
} 

Message.WriteCount() ; 
Message.WriteTurn() ; 
Message.repaint() ; 
Board.turnning = false ; 
Board.loop = 1 ; 
Comp.thinking = true ; 
Board.MoveThis.resume() ; 
Board.repaint() ; 
} 

public void Reset() { testworks.runtime.jrun.SegHit(8, 1);

level = level_swap ; 

Data_init() ; 

tricks = 0 ; 

color = black ; 

Comp.comp_color = white ; 

Board.draw_board() ; 

Board.draw_all_pieces() ; 

Board.repaint() ; 

Message.WriteCount() ; 

Message.WriteTurn() ; 

Message.repaint() ; 
} 

public final boolean turn_up(Object obje , int column , int row , int color) { testworks.runtime.jrun.SegHit(9, 1);

int column_d , row_d ; 
boolean OX = false ; 
int board[][] =(int[][]) obje ; 

if (testworks.runtime.jrun.ExpHit(9, 2, board[column ][row ] != 0) ){ 
return OX ; 
} 

for (int c = - 1 ; testworks.runtime.jrun.ExpHit(9, 4, c< 2 ); c++) { 
END : for (int r = - 1 ; testworks.runtime.jrun.ExpHit(9, 6, r< 2 ); r++) { 

column_d = column + c ; 
row_d = row + r ; 

if (testworks.runtime.jrun.ExpHit(9, 8, column_d < 0 || column_d > 7 || row_d < 0 || row_d > 7) ){ 
continue END ; 
} 
else if (testworks.runtime.jrun.ExpHit(9, 10, board[column_d ][row_d ] != - 1 * color) ){ 
continue END ; 
} 

do { 
column_d += c ; 
row_d += r ; 

if (testworks.runtime.jrun.ExpHit(9, 12, column_d < 0 || column_d > 7 || row_d < 0 || row_d > 7) ){ 
continue END ; 
} 
} while (testworks.runtime.jrun.ExpHit(9, 14, board[column_d ][row_d ] == - 1 * color) ); 

if (testworks.runtime.jrun.ExpHit(9, 16, board[column_d ][row_d ] == color) ){ 
do { 
OX = true ; 
column_d -= c ; 
row_d -= r ; 
board[column_d ][row_d ] = color ; 
} while (testworks.runtime.jrun.ExpHit(9, 18, column_d != column || row_d != row) ); 
} 
} 
} 
return OX ; 
} 

public void Register(String s) { testworks.runtime.jrun.SegHit(10, 1);

if (testworks.runtime.jrun.ExpHit(10, 2, ! registering && ! registeringe) ){ 
return ; 
} 

try { 
URL url = new URL(s) ; 
getAppletContext().showDocument(url) ; 
} catch(MalformedURLException e) { } 
} 
} 

class BOARD extends Panel implements Runnable { 

Jothello jothe ; 

Graphics graphic ; 
Image image ; 

Thread MoveThis ; 
final int sleeping = 200 ; 
boolean turnning = false ; 
int loop = 0 ; 

final int width = 241 ; 
final int height = 241 ; 
final int line_terval = 30 ; 
final int diameter = 25 ; 

int draw_color ; 
int count = 0 ; 
int turn_up_pieces[][] = new int[19 ][2 ] ; 

Color shade ; 

BOARD(Jothello jothello) { testworks.runtime.jrun.SegHit(11, 1);

jothe = jothello ; 
} 

public void init() { testworks.runtime.jrun.SegHit(12, 1);

image = createImage(width , height) ; 
graphic = image.getGraphics() ; 

shade = new Color(0 , 60 , 0) ; 

MoveThis = new Thread(this) ; 
MoveThis.start() ; 
//MoveThis.suspend() ; 
} 

public void draw_board() { testworks.runtime.jrun.SegHit(13, 1);

graphic.setColor(Color.lightGray) ; 
graphic.fillRect(0 , 0 , width , height) ; 
graphic.setColor(new Color(20 , 150 , 20)) ; 
graphic.fillRect(0 , 0 , 8 * line_terval , 8 * line_terval) ; 
graphic.setColor(Color.black) ; 
for (int line = 0 ; testworks.runtime.jrun.ExpHit(13, 2, line< 9 ); line++) { 
graphic.drawLine(line * line_terval , 0 , line * line_terval , 8 * line_terval) ; 
graphic.drawLine(0 , line * line_terval , 8 * line_terval , line * line_terval) ; 
} 
} 

public void draw_all_pieces() { testworks.runtime.jrun.SegHit(14, 1);

for (int column = 0 ; testworks.runtime.jrun.ExpHit(14, 2, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(14, 4, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(14, 6, jothe.blank != jothe.board[column ][row ]) ){ 
draw_a_piece(column , row , jothe.board[column ][row ]) ; 
} 
} 
} 
} 

public void draw_a_piece(int column , int row , int color) { testworks.runtime.jrun.SegHit(15, 1);

int x = line_terval * row +(line_terval - diameter) / 2 ; 
int y = line_terval * column +(line_terval - diameter) / 2 ; 

graphic.setColor(shade) ; 
graphic.fillOval(x - 1 , y - 1 , diameter + 3 , diameter + 3) ; 

if (testworks.runtime.jrun.ExpHit(15, 2, color == jothe.black) ){ 
graphic.setColor(new Color(20 , 20 , 20)) ; 
graphic.fillOval(x - 1 , y - 1 , diameter + 2 , diameter + 2) ; 
graphic.setColor(Color.darkGray) ; 
graphic.fillOval(x + 1 , y + 1 , diameter - 4 , diameter - 4) ; 
graphic.setColor(new Color(48 , 48 , 48)) ; 
graphic.fillOval(x + 3 , y + 3 , diameter - 5 , diameter - 5) ; 
} 
else { 
graphic.setColor(new Color(55 , 55 , 55)) ; 
graphic.fillOval(x - 1 , y - 1 , diameter + 2 , diameter + 2) ; 
graphic.setColor(new Color(80 , 80 , 80)) ; 
graphic.fillOval(x - 1 , y - 1 , diameter + 1 , diameter + 1) ; 
graphic.setColor(new Color(128 , 128 , 128)) ; 
graphic.fillOval(x , y , diameter - 1 , diameter - 1) ; 
graphic.setColor(new Color(160 , 160 , 160)) ; 
graphic.fillOval(x + 1 , y + 1 , diameter - 2 , diameter - 2) ; 
graphic.setColor(Color.white) ; 
graphic.fillOval(x , y , diameter - 2 , diameter - 2) ; 
graphic.setColor(new Color(220 , 220 , 220)) ; 
graphic.fillOval(x + 2 , y + 2 , diameter - 4 , diameter - 4) ; 
} 
} 

public void draw_pieces() { testworks.runtime.jrun.SegHit(16, 1);

int column = turn_up_pieces[count ][0 ] ; 
int row = turn_up_pieces[count ][1 ] ; 
turn_up_pieces[count ][0 ] = 0 ; 
turn_up_pieces[count ][1 ] = 0 ; 
count-- ; 

draw_a_piece(column , row , draw_color ) ; 
} 

public synchronized void update(Graphics g) { testworks.runtime.jrun.SegHit(17, 1);

if (testworks.runtime.jrun.ExpHit(17, 2, turnning) ){ 

draw_pieces() ; 

if (testworks.runtime.jrun.ExpHit(17, 4, count <= 0) ){ 
count = 0 ; 
turnning = false ; 
} 
if (testworks.runtime.jrun.ExpHit(17, 6, ! turnning) ){ 
jothe.color *= - 1 ; 
jothe.Message.WriteTurn() ; 
jothe.Message.repaint() ; 
jothe.Comp.thinking = ! jothe.Comp.thinking ; 
if (testworks.runtime.jrun.ExpHit(17, 8, ! jothe.Comp.thinking) ){ 
//MoveThis.suspend() ; 
} 
} 

} 
g.drawImage(image , 0 , 0 , null) ; 

if (testworks.runtime.jrun.ExpHit(17, 10, jothe.Comp.thinking && ! turnning && loop >= 3) ){ 
loop = 0 ; 
//MoveThis.suspend() ; 
if (testworks.runtime.jrun.ExpHit(17, 12, jothe.Comp.ThinkOut()) ){ 
MoveThis.resume() ; 
get_turn_up_pieces(jothe.board , jothe.Comp.column , jothe.Comp.row , jothe.Comp.comp_color) ; 
jothe.turn_up(jothe.board , jothe.Comp.column , jothe.Comp.row , jothe.Comp.comp_color) ; 
draw_color = jothe.Comp.comp_color ; 
jothe.undo_color[jothe.tricks ] = jothe.Comp.comp_color ; 
jothe.undo_column[jothe.tricks ] = jothe.Comp.column ; 
jothe.undo_row[jothe.tricks ] = jothe.Comp.row ; 
jothe.tricks++ ; 
turnning = true ; 
jothe.Message.WriteCount() ; 
jothe.Message.repaint() ; 
} 
else { 
jothe.color = - 1 * jothe.color ; 
jothe.Message.WriteTurn() ; 
jothe.Message.repaint() ; 
jothe.Comp.thinking = false ; 
} 
} 

if (testworks.runtime.jrun.ExpHit(17, 14, jothe.Comp.comp_color == jothe.color && ! turnning) ){ 
jothe.Comp.thinking = true ; 
loop++ ; 
} 
} 

public void paint(Graphics g) { testworks.runtime.jrun.SegHit(18, 1);

graphic.drawImage(image , 0 , 0 , null) ; 
g.drawImage(image , 0 , 0 , null) ; 
} 

public boolean mouseDown(Event evt , int x , int y) { testworks.runtime.jrun.SegHit(19, 1);

if (testworks.runtime.jrun.ExpHit(19, 2, turnning) ){ 
return false ; 
} 

int row = getPosition(x) ; 
int column = getPosition(y) ; 

if (testworks.runtime.jrun.ExpHit(19, 4, row < 0 || row > 7 || column < 0 || column > 7) ){ 
return false ; 
} 

if (testworks.runtime.jrun.ExpHit(19, 6, get_turn_up_pieces(jothe.board , column , row , jothe.color)) ){ 
jothe.turn_up(jothe.board , column , row , jothe.color) ; 
draw_color = jothe.color ; 
jothe.undo_color[jothe.tricks ] = jothe.color ; 
jothe.undo_column[jothe.tricks ] = column ; 
jothe.undo_row[jothe.tricks ] = row ; 
jothe.tricks++ ; 

jothe.Message.WriteCount() ; 
jothe.Message.repaint() ; 

turnning = true ; 
MoveThis.resume() ; 
} 
return true ; 
} 

public void run() { testworks.runtime.jrun.SegHit(20, 1);

while (testworks.runtime.jrun.ExpHit(20, 2, true) ){ 
try { 
repaint() ; 
MoveThis.sleep(sleeping) ; 
} catch(InterruptedException e) { } 
} 
} 

public int getPosition(int num) { testworks.runtime.jrun.SegHit(21, 1);

return num / line_terval ; 
} 

public boolean get_turn_up_pieces(Object obje , int column , int row , int color) { testworks.runtime.jrun.SegHit(22, 1);

int column_d , row_d ; 
boolean OX = false ; 
int board[][] =(int[][]) obje ; 

if (testworks.runtime.jrun.ExpHit(22, 2, board[column ][row ] != jothe.blank) ){ 
return OX ; 
} 

for (int c = - 1 ; testworks.runtime.jrun.ExpHit(22, 4, c< 2 ); c++) { 
END : for (int r = - 1 ; testworks.runtime.jrun.ExpHit(22, 6, r< 2 ); r++) { 

column_d = column + c ; 
row_d = row + r ; 

if (testworks.runtime.jrun.ExpHit(22, 8, column_d < 0 || column_d > 7 || row_d < 0 || row_d > 7) ){ 
continue END ; 
} 
else if (testworks.runtime.jrun.ExpHit(22, 10, board[column_d ][row_d ] != - 1 * color) ){ 
continue END ; 
} 

do { 
column_d += c ; 
row_d += r ; 

if (testworks.runtime.jrun.ExpHit(22, 12, column_d < 0 || column_d > 7 || row_d < 0 || row_d > 7) ){ 
continue END ; 
} 
} while (testworks.runtime.jrun.ExpHit(22, 14, board[column_d ][row_d ] == - 1 * color) ); 

if (testworks.runtime.jrun.ExpHit(22, 16, board[column_d ][row_d ] == color) ){ 
do { 
OX = true ; 
column_d -= c ; 
row_d -= r ; 

if (testworks.runtime.jrun.ExpHit(22, 18, !(column == column_d && row == row_d)) ){ 
count++ ; 
turn_up_pieces[count ][0 ] = column_d ; 
turn_up_pieces[count ][1 ] = row_d ; 
} 
} while (testworks.runtime.jrun.ExpHit(22, 20, column_d != column || row_d != row) ); 
} 
} 
} 

if (testworks.runtime.jrun.ExpHit(22, 22, OX == true) ){ 
count++ ; 
turn_up_pieces[count ][0 ] = column ; 
turn_up_pieces[count ][1 ] = row ; 
} 

return OX ; 
} 
} 

class COMP_DATA { 

int possible ; 
int number ; 
int corner ; 
} 

class COMP { 

Jothello jothe ; 

boolean thinking = false ; 

int column , row ; 
int comp_color ; 

int corner[][] = new int[8 ][8 ] ; 
int poor[][] = new int[8 ][8 ] ; 
int end[][] = new int[8 ][8 ] ; 
boolean can[][] = new boolean[8 ][8 ] ; 

COMP_DATA data ; 

COMP(Jothello jothello) { testworks.runtime.jrun.SegHit(23, 1);

jothe = jothello ; 
comp_color = jothe.white ; 
} 

public boolean ThinkOut() { testworks.runtime.jrun.SegHit(24, 1);

int count = 0 ; 
int board_now[][] = new int[8 ][8 ] ; 

Comp_Data_init() ; 

copy(board_now , '<' , jothe.board) ; 

if (testworks.runtime.jrun.ExpHit(24, 2, jothe.black_num + jothe.white_num > 64 - jothe.level_up) ){ 
jothe.level = 64 -(jothe.black_num + jothe.white_num) ; 
} 
else if (testworks.runtime.jrun.ExpHit(24, 4, jothe.black_num + jothe.white_num + 3 > 64 - jothe.level_up) ){ 
jothe.level = jothe.level_swap + 3 ; 
} 

for (int column = 0 ; testworks.runtime.jrun.ExpHit(24, 6, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(24, 8, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(24, 10, jothe.turn_up(board_now , column , row , jothe.Comp.comp_color)) ){ 
count++ ; 
this.column = column ; 
this.row = row ; 
can[column ][row ] = true ; 
data = preSee(board_now , 0 , - 1 * comp_color) ; 
end[column ][row ] = data.number ; 
poor[column ][row ] = data.possible ; 
corner[column ][row ] = data.corner ; 
copy(board_now , '<' , jothe.board) ; 
} 
} 
} 

if (testworks.runtime.jrun.ExpHit(24, 12, count == 0) ){ 
return false ; 
} 

decide() ; 

return true ; 
} 

public COMP_DATA end_line(Object obj , int color) { testworks.runtime.jrun.SegHit(25, 1);

int board[][] =(int[][]) obj ; 
COMP_DATA data = new COMP_DATA() ; 

data.number = piece_counter(board) ; 
data.possible = possible_counter(board , color) ; 
data.corner = corner_counter(board , color) ; 

return data ; 
} 

public int corner_counter(Object obj , int color) { testworks.runtime.jrun.SegHit(26, 1);

int board[][] =(int[][]) obj ; 
int count = 0 ; 

for (int column = 0 ; testworks.runtime.jrun.ExpHit(26, 2, column< 8 ); column += 7) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(26, 4, row< 8 ); row += 7) { 
if (testworks.runtime.jrun.ExpHit(26, 6, jothe.board[column ][row ] == jothe.blank && board[column ][row ] == comp_color) ){ 
count++ ; 
} 
if (testworks.runtime.jrun.ExpHit(26, 8, color == comp_color && possible(board , column , row , comp_color)) ){ 
count++ ; 
} 
if (testworks.runtime.jrun.ExpHit(26, 10, jothe.board[column ][row ] == jothe.blank && board[column ][row ] == - 1 * comp_color) ){ 
count-- ; 
} 
if (testworks.runtime.jrun.ExpHit(26, 12, color != comp_color && possible(board , column , row , - 1 * comp_color)) ){ 
count-- ; 
} 
} 
} 
return count ; 
} 

public int possible_counter(Object obj , int color) { testworks.runtime.jrun.SegHit(27, 1);

int board[][] =(int[][]) obj ; 
int count = 0 ; 

if (testworks.runtime.jrun.ExpHit(27, 2, color == comp_color) ){ 
for (int column = 0 ; testworks.runtime.jrun.ExpHit(27, 4, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(27, 6, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(27, 8, possible(board , column , row , color)) ){ 
count++ ; 
} 
} 
} 
} 
else { 
for (int column = 0 ; testworks.runtime.jrun.ExpHit(27, 10, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(27, 12, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(27, 14, ! possible(board , column , row , color)) ){ 
count++ ; 
} 
} 
} 
} 
return count ; 
} 

public int piece_counter(Object obj) { testworks.runtime.jrun.SegHit(28, 1);

int board[][] =(int[][]) obj ; 
int count = 0 ; 

for (int column = 0 ; testworks.runtime.jrun.ExpHit(28, 2, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(28, 4, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(28, 6, board[column ][row ] == comp_color) ){ 
count++ ; 
} 
} 
} 
return count ; 
} 

public void Comp_Data_init() { testworks.runtime.jrun.SegHit(29, 1);

for (int column = 0 ; testworks.runtime.jrun.ExpHit(29, 2, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(29, 4, row< 8 ); row++) { 
end[column ][row ] = 0 ; 
can[column ][row ] = false ; 
poor[column ][row ] = 0 ; 
corner[column ][row ] = 0 ; 
} 
} 
} 

public final COMP_DATA preSee(Object obje , int num , int color) { testworks.runtime.jrun.SegHit(30, 1);

int board_pre[][] =(int[][]) obje ; 
int board_now[][] = new int[8 ][8 ] ; 

int count = 0 ; 
int end_num1 , end_num2 , end_num3 ; 
int end_num_d = 0 ; 

COMP_DATA data = new COMP_DATA() ; 

if (testworks.runtime.jrun.ExpHit(30, 2, color == comp_color) ){ 
end_num1 = 0 ; 
end_num2 = 0 ; 
end_num3 = - 10 ; 
} 
else { 
end_num1 = 100 ; 
end_num2 = 100 ; 
end_num3 = 10 ; 
} 

copy(board_now , '<' , board_pre) ; 

if (testworks.runtime.jrun.ExpHit(30, 4, num < jothe.level) ){ 
for (int column = 0 ; testworks.runtime.jrun.ExpHit(30, 6, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(30, 8, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(30, 10, jothe.turn_up(board_now , column , row , color)) ){ 
count++ ; 
data = preSee(board_now , num + 1 , - 1 * color ) ; 
if (testworks.runtime.jrun.ExpHit(30, 12, (color == comp_color && data.number > end_num1) ||(color != comp_color && data.number < end_num1)) ){ 
end_num1 = data.number ; 
} 
if (testworks.runtime.jrun.ExpHit(30, 14, (color == comp_color && data.possible > end_num2) ||(color != comp_color && data.possible < end_num2)) ){ 
end_num2 = data.possible ; 
} 
if (testworks.runtime.jrun.ExpHit(30, 16, (color == comp_color && data.corner > end_num3) ||(color != comp_color && data.corner < end_num3)) ){ 
end_num3 = data.corner ; 
} 
copy(board_now , '<' , board_pre) ; 
} 
} 
} 

if (testworks.runtime.jrun.ExpHit(30, 18, count == 0) ){ 
data = preSee(board_now , num + 1 , - 1 * color ) ; 
if (testworks.runtime.jrun.ExpHit(30, 20, (color == comp_color && data.number > end_num1) ||(color != comp_color && data.number < end_num1)) ){ 
end_num1 = data.number ; 
} 
if (testworks.runtime.jrun.ExpHit(30, 22, (color == comp_color && data.possible > end_num2) ||(color != comp_color && data.possible < end_num2)) ){ 
end_num2 = data.possible ; 
} 
if (testworks.runtime.jrun.ExpHit(30, 24, (color == comp_color && data.corner > end_num3) ||(color != comp_color && data.corner < end_num3)) ){ 
end_num3 = data.corner ; 
} 
} 
data.number = end_num1 ; 
data.possible = end_num2 ; 
data.corner = end_num3 ; 
} 
else { 
return end_line(board_pre , color ) ; 
} 

return data ; 
} 

public void decide() { testworks.runtime.jrun.SegHit(31, 1);

int count1 = - 64 ; 
int count2 = 0 ; 
int count3 = - 10 ; 

for (int column = 1 ; testworks.runtime.jrun.ExpHit(31, 2, column< 7 ); column += 5) { 
for (int row = 1 ; testworks.runtime.jrun.ExpHit(31, 4, row< 7 ); row += 5) { 
if (testworks.runtime.jrun.ExpHit(31, 6, no_corner(jothe.board , column , row)) ){ 
corner[column ][row ] = - 10 ; 
} 
} 
} 

for (int column = 1 ; testworks.runtime.jrun.ExpHit(31, 8, column< 7 ); column += 5) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(31, 10, row< 8 ); row += 7) { 
int co1 = 7 ; 
int co2 = 5 ; 
if (testworks.runtime.jrun.ExpHit(31, 12, column == 1) ){ 
co1 = 0 ; 
co2 = 2 ; 
} 
if (testworks.runtime.jrun.ExpHit(31, 14, can[column ][row ]) ){ 
if (testworks.runtime.jrun.ExpHit(31, 16, jothe.board[co2 ][row ] == jothe.blank && jothe.board[co1 ][row ] == jothe.blank) ){ 
corner[column ][row ] = - 10 ; 
} 
} 
if (testworks.runtime.jrun.ExpHit(31, 18, can[row ][column ]) ){ 
if (testworks.runtime.jrun.ExpHit(31, 20, jothe.board[row ][co2 ] == jothe.blank && jothe.board[row ][co1 ] == jothe.blank) ){ 
corner[row ][column ] = - 10 ; 
} 
} 
} 
} 

for (int column = 0 ; testworks.runtime.jrun.ExpHit(31, 22, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(31, 24, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(31, 26, can[column ][row ]) ){ 
if (testworks.runtime.jrun.ExpHit(31, 28, corner[column ][row ] >= count3) ){ 
count3 = corner[column ][row ] ; 
this.column = column ; 
this.row = row ; 
if (testworks.runtime.jrun.ExpHit(31, 30, poor[column ][row ] >= count1) ){ 
count1 = poor[column ][row ] ; 
this.column = column ; 
this.row = row ; 
if (testworks.runtime.jrun.ExpHit(31, 32, end[column ][row ] >= count2) ){ 
count2 = end[column ][row ] ; 
this.column = column ; 
this.row = row ; 
} 
} 
} 
} 
} 
} 

still(this.column , this.row) ; 

if (testworks.runtime.jrun.ExpHit(31, 34, jothe.level == jothe.level_up) ){ 
count2 = 0 ; 
for (int column = 0 ; testworks.runtime.jrun.ExpHit(31, 36, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(31, 38, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(31, 40, can[column ][row ]) ){ 
if (testworks.runtime.jrun.ExpHit(31, 42, end[column ][row ] >= count2) ){ 
count2 = end[column ][row ] ; 
this.column = column ; 
this.row = row ; 
} 
} 
} 
} 
} 
} 

public void still(int column , int row) { testworks.runtime.jrun.SegHit(32, 1);

int board_d[][] = new int[8 ][8 ] ; 

boolean stl = false ; 

copy(board_d , '<' , jothe.board) ; 
jothe.turn_up(board_d , column , row , comp_color) ; 

for (int column1 = 0 ; testworks.runtime.jrun.ExpHit(32, 2, column1< 8 ); column1 += 7) { 
for (int row1 = 0 ; testworks.runtime.jrun.ExpHit(32, 4, row1< 8 ); row1 += 7) { 
if (testworks.runtime.jrun.ExpHit(32, 6, possible(board_d , column1 , row1 , - 1 * comp_color)) ){ 
stl = true ; 
} 
} 
} 

int count = 0 ; 

copy(board_d , '<' , jothe.board) ; 

if (testworks.runtime.jrun.ExpHit(32, 8, stl) ){ 
for (int column1 = 1 ; testworks.runtime.jrun.ExpHit(32, 10, column1< 7 ); column1 += 5) { 
for (int row1 = 1 ; testworks.runtime.jrun.ExpHit(32, 12, row1< 7 ); row1 += 5) { 
if (testworks.runtime.jrun.ExpHit(32, 14, jothe.turn_up(board_d , column1 , row1 , comp_color)) ){ 
for (int column2 = 0 ; testworks.runtime.jrun.ExpHit(32, 16, column2< 8 ); column2 += 7) { 
for (int row2 = 0 ; testworks.runtime.jrun.ExpHit(32, 18, row2< 8 ); row2 += 7) { 
if (testworks.runtime.jrun.ExpHit(32, 20, ! possible(board_d , column2 , row2 , - 1 * comp_color)) ){ 
count++ ; 
} 
} 
} 
if (testworks.runtime.jrun.ExpHit(32, 22, count == 4) ){ 
this.column = column1 ; 
this.row = row1 ; 
} 
count = 0 ; 
copy(board_d , '<' , jothe.board) ; 
} 
} 
} 
} 
} 

public boolean no_corner(Object obje , int column , int row) { testworks.runtime.jrun.SegHit(33, 1);

int board[][] =(int[][]) obje ; 
int co = 0 , ro = 0 ; 

if (testworks.runtime.jrun.ExpHit(33, 2, column == 6) ){ 
co = 7 ; 
} 

if (testworks.runtime.jrun.ExpHit(33, 4, row == 6) ){ 
ro = 7 ; 
} 

if (testworks.runtime.jrun.ExpHit(33, 6, board[co ][ro ] == jothe.blank) ){ 
return true ; 
} 

return false ; 
} 

public final void copy(Object obje1 , char chr , Object obje2) { testworks.runtime.jrun.SegHit(34, 1);

int board1[][] =(int[][]) obje1 ; 
int board2[][] =(int[][]) obje2 ; 

if (testworks.runtime.jrun.ExpHit(34, 2, chr == '<') ){ 
for (int column = 0 ; testworks.runtime.jrun.ExpHit(34, 4, column< 8 ); column++) { 
System.arraycopy(board2[column ] , 0 , board1[column ] , 0 , 8) ; 
} 
} 
else { 
for (int column = 0 ; testworks.runtime.jrun.ExpHit(34, 6, column< 8 ); column++) { 
System.arraycopy(board1[column ] , 0 , board2[column ] , 0 , 8) ; 
} 
} 
} 

public boolean possible(Object obje , int column , int row , int color) { testworks.runtime.jrun.SegHit(35, 1);

int column_d , row_d ; 
int board[][] =(int[][]) obje ; 

if (testworks.runtime.jrun.ExpHit(35, 2, board[column ][row ] != 0) ){ 
return false ; 
} 

for (int c = - 1 ; testworks.runtime.jrun.ExpHit(35, 4, c< 2 ); c++) { 
END : for (int r = - 1 ; testworks.runtime.jrun.ExpHit(35, 6, r< 2 ); r++) { 

column_d = column + c ; 
row_d = row + r ; 

if (testworks.runtime.jrun.ExpHit(35, 8, column_d < 0 || column_d > 7 || row_d < 0 || row_d > 7) ){ 
continue END ; 
} 
else if (testworks.runtime.jrun.ExpHit(35, 10, board[column_d ][row_d ] != - 1 * color) ){ 
continue END ; 
} 

do { 
column_d += c ; 
row_d += r ; 

if (testworks.runtime.jrun.ExpHit(35, 12, column_d < 0 || column_d > 7 || row_d < 0 || row_d > 7) ){ 
continue END ; 
} 
} while (testworks.runtime.jrun.ExpHit(35, 14, board[column_d ][row_d ] == - 1 * color) ); 

if (testworks.runtime.jrun.ExpHit(35, 16, board[column_d ][row_d ] == color) ){ 
return true ; 
} 
} 
} 

return false ; 
} 
} 

class MESSAGE extends Panel { 

Jothello jothe ; 

Image image ; 
Graphics graphic ; 

MESSAGE(Jothello jothello) { testworks.runtime.jrun.SegHit(36, 1);

jothe = jothello ; 
} 

public void init() { testworks.runtime.jrun.SegHit(37, 1);

image = createImage(jothe.Board.width , jothe.Board.line_terval) ; 
graphic = image.getGraphics() ; 
graphic.setColor(Color.lightGray) ; 
graphic.fillRect(0 , 0 , jothe.Board.width , jothe.Board.line_terval) ; 
graphic.setFont(new Font("TimesRoman" , Font.BOLD , 15)) ; 
reliefString("move:" , 3 , jothe.Board.line_terval - 5) ; 
reliefString("count:" , 123 , jothe.Board.line_terval - 5) ; 
} 

public void WriteCount() { testworks.runtime.jrun.SegHit(38, 1);

String black , white ; 

count() ; 

black = String.valueOf(jothe.black_num) ; 
white = String.valueOf(jothe.white_num) ; 

if (testworks.runtime.jrun.ExpHit(38, 2, jothe.black_num < 10) ){ 
black = "  " + black ; 
} 

if (testworks.runtime.jrun.ExpHit(38, 4, jothe.white_num < 10) ){ 
white = " " + white ; 
} 

graphic.setColor(Color.lightGray) ; 
graphic.fillRect(168 , 0 , 75 , jothe.Board.line_terval) ; 
graphic.setFont(new Font("TimesRoman" , Font.BOLD , 25)) ; 
writeString(black + " :" , 169 , jothe.Board.line_terval - 5 , false) ; 
writeString(white , 210 , jothe.Board.line_terval - 5 , true) ; 
} 

public void WriteTurn() { testworks.runtime.jrun.SegHit(39, 1);

int num = 0 ; 

graphic.setColor(Color.lightGray) ; 
graphic.fillRect(44 , 0 , 70 , 31) ; 
if (testworks.runtime.jrun.ExpHit(39, 2, jothe.color == jothe.black) ){ 
writeString("Black" , 45 , jothe.Board.line_terval - 5 , false) ; 
} 
else { 
writeString("White" , 45 , jothe.Board.line_terval - 5 , true) ; 
} 

count() ; 

int board[][] = new int[8 ][8 ] ; 

jothe.Comp.copy(board , '<' , jothe.board) ; 

for (int column = 0 ; testworks.runtime.jrun.ExpHit(39, 4, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(39, 6, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(39, 8, jothe.turn_up(board , column , row , jothe.color)) ){ 
num++ ; 
jothe.Comp.copy(board , '<' , jothe.board) ; 
} 
} 
} 

if (testworks.runtime.jrun.ExpHit(39, 10, num == 0) ){ 
for (int column = 0 ; testworks.runtime.jrun.ExpHit(39, 12, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(39, 14, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(39, 16, jothe.turn_up(board , column , row , - 1 * jothe.color)) ){ 
num++ ; 
jothe.Comp.copy(board , '<' , jothe.board) ; 
} 
} 
} 
if (testworks.runtime.jrun.ExpHit(39, 18, num == 0) ){ 
graphic.setColor(Color.lightGray) ; 
graphic.fillRect(44 , 0 , 70 , 31) ; 

count() ; 

String s = "" ; 

if (testworks.runtime.jrun.ExpHit(39, 20, jothe.registeringe) ){ 
s = "http://www.ritsumei.ac.jp/bkc/~sph40086/cgi-bin/jothello-e.cgi?" ; 
} 
else if (testworks.runtime.jrun.ExpHit(39, 22, jothe.registering) ){ 
s = "http://www.ritsumei.ac.jp/bkc/~sph40086/cgi-bin/jothello.cgi?" ; 
} 

s += "w=" ; 

if (testworks.runtime.jrun.ExpHit(39, 24, jothe.Comp.comp_color == jothe.black) ){ 
if (testworks.runtime.jrun.ExpHit(39, 26, jothe.black_num > jothe.white_num) ){ 
s += "c&c=w&" ; 
} 
else if (testworks.runtime.jrun.ExpHit(39, 28, jothe.black_num < jothe.white_num) ){ 
s += "u&c=w&" ; 
} 
else { 
s += "d&c=w&" ; 
} 
s += "cn=" ; 
s += String.valueOf(jothe.black_num) ; 
s += "&un=" ; 
s += String.valueOf(jothe.white_num) ; 
} 
else { 
if (testworks.runtime.jrun.ExpHit(39, 30, jothe.black_num > jothe.white_num) ){ 
s += "u&c=b&" ; 
} 
else if (testworks.runtime.jrun.ExpHit(39, 32, jothe.black_num < jothe.white_num) ){ 
s += "c&c=b&" ; 
} 
else { 
s += "d&c=b&" ; 
} 
s += "cn=" ; 
s += String.valueOf(jothe.white_num) ; 
s += "&un=" ; 
s += String.valueOf(jothe.black_num) ; 
} 

s += "&l=" ; 
s += String.valueOf(jothe.level_swap) ; 

jothe.Register(s) ; 
writeString("End" , 60 , jothe.Board.line_terval - 5 , false) ; 
} 
} 
} 

public void count() { testworks.runtime.jrun.SegHit(40, 1);

jothe.black_num = 0 ; 
jothe.white_num = 0 ; 

for (int column = 0 ; testworks.runtime.jrun.ExpHit(40, 2, column< 8 ); column++) { 
for (int row = 0 ; testworks.runtime.jrun.ExpHit(40, 4, row< 8 ); row++) { 
if (testworks.runtime.jrun.ExpHit(40, 6, jothe.board[column ][row ] == jothe.black) ){ 
jothe.black_num++ ; 
} 
else if (testworks.runtime.jrun.ExpHit(40, 8, jothe.board[column ][row ] == jothe.white) ){ 
jothe.white_num++ ; 
} 
} 
} 
} 

public void writeString(String s , int x , int y , boolean hollow) { testworks.runtime.jrun.SegHit(41, 1);

graphic.setColor(Color.black) ; 
graphic.drawString(s , x - 1 , y) ; 
graphic.drawString(s , x + 1 , y) ; 
graphic.drawString(s , x , y - 1) ; 
graphic.drawString(s , x , y + 1) ; 

if (testworks.runtime.jrun.ExpHit(41, 2, hollow) ){ 
graphic.setColor(Color.white) ; 
graphic.drawString(s , x , y) ; 
} 
} 

public void reliefString(String s , int x , int y) { testworks.runtime.jrun.SegHit(42, 1);

graphic.setColor(Color.white) ; 
graphic.drawString(s , x - 1 , y - 1) ; 
graphic.setColor(Color.darkGray) ; 
graphic.drawString(s , x + 1 , y + 1) ; 
graphic.setColor(Color.lightGray) ; 
graphic.drawString(s , x , y) ; 
} 

public void paint(Graphics g) { testworks.runtime.jrun.SegHit(43, 1);

g.drawImage(image , 0 , 0 , null) ; 
} 

public synchronized void update(Graphics g) { testworks.runtime.jrun.SegHit(44, 1);

g.drawImage(image , 0 , 0 , null) ; 
} 
} 
