1 1 2 2 2.1 Java......... 2 2.2................................. 3 2.3.................................. 3 3 4 3.1....................................



Similar documents
Battle Ship

: Java JavaSript

改訂版 :基本的な文字化の原則(Basic Transcription System for Japanese: BTSJ)

‚æ2›ñ C„¾„ê‡Ìš|

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

(search: ) [1] ( ) 2 (linear search) (sequential search) 1

PowerPoint Presentation

:30 12:00 I. I VI II. III. IV. a d V. VI

‚æ4›ñ

C言語によるアルゴリズムとデータ構造

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

untitled

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

Microsoft PowerPoint - C_Programming(3).pptx

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

:30 12:00 I. I VI II. III. IV. a d V. VI

I J

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D

P03.ppt

Microsoft PowerPoint - CproNt02.ppt [互換モード]

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

Prog1_14th

A/B (2018/06/08) Ver kurino/2018/soft/soft.html A/B

解きながら学ぶC++入門編

●70974_100_AC009160_KAPヘ<3099>ーシス自動車約款(11.10).indb

main

8 if switch for while do while 2

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

10

Taro-リストⅢ(公開版).jtd

Microsoft PowerPoint - kougi9.ppt

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:

C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 新装版 1 刷発行時のものです.

超初心者用

新・明解C言語 ポインタ完全攻略

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

C B

数値計算

C ( ) C ( ) C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C mandata mandata ( ) name age income mandata ( ) mandat

Microsoft Word - Cプログラミング演習(8)

P06.ppt

Lecture on

REALV5_A4…p_Ł\1_4A_OCF

untitled

「都市から地方への人材誘致・移住促進に関する調査」

<91498EE88CA D815B2E786C73>

〔 大 会 役 員 〕

橡本体資料+参考条文.PDF

K227 Java 2

卒 業 研 究 報 告.PDF

ディジタル信号処理

Java演習(4) -- 変数と型 --

Microsoft PowerPoint - C言語の復習(配布用).ppt [互換モード]

Microsoft PowerPoint - 14Chap17.ppt

19 3!! (+) (>) (++) (+=) for while 3.1!! (20, 20) (1)(Blocks1.java) import javax.swing.japplet; import java.awt.graphics;

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved

1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

O(N) ( ) log 2 N

Java updated

コーディング基準.PDF

数値計算

<4D F736F F D20438CBE8CEA8D758DC F0939A82C282AB2E646F63>

r08.dvi

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou

Microsoft Word - C.....u.K...doc

ohp08.dvi

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

プログラミング基礎

x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x i ) A(x i ) = h 2 {f(x i) + f(x i+1 ) = h {f(a + i h) + f(a + (i + 1) h), (2) 2 a b n A(x i )


PowerPoint プレゼンテーション

10/8 Finder,, 1 1. Finder MAC OS X 2. ( ) MAC OS X Java ( ) 3. MAC OS X Java ( ) / 10

Microsoft PowerPoint - program.ppt [互換モード]

解きながら学ぶJava入門編

fp.gby

r07.dvi

18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf("hello World\n"); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o

file:///D|/C言語の擬似クラス.txt

ohp07.dvi

P05.ppt


ex01.dvi

新版明解C言語 実践編

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±

橡Pro PDF

明解Javaによるアルゴリズムとデータ構造

ポインタ変数

橡Taro9-生徒の活動.PDF

#"

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

Java プログラミング Ⅰ 7 回目 switch 文と論理演算子 今日の講義講義で学ぶ内容 switch 文 論理演算子 条件演算子 条件判断文 3 switch 文 switch 文 式が case のラベルと一致する場所から直後の break; まで処理しますどれにも一致致しない場合 def

新・明解Java入門

(1 ) scanf(

Microsoft PowerPoint - lecture201509c_1.pptx

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved

Microsoft PowerPoint - 15Game.ppt

Transcription:

06H082

1 1 2 2 2.1 Java......... 2 2.2................................. 3 2.3.................................. 3 3 4 3.1..................................... 4 3.2 GP..................................... 5 3.3 Battle Ship.............................................. 6 3.4 GP.............................................. 6 4 7 4.1 Practice................................................ 8 4.2 Verification.............................................. 9 4.3 Score.................................................. 10 5 11 5.1............................................... 12 A 14 A.1 Practice................................................ 14 A.2 Verification.............................................. 28 A.3 Score.................................................. 39

Battle Ship GP(Game Programme) GP Battle Ship

1 *1 *2 1 1 *3 GP *4 *1 *2 *3 2 1) 2) *4 Game Programme : 1

2 2 Java [1] [2] 2.1 Java Java *5 1 *5 2

2.2 on Squeak * 6 on Squeak on Squeak on Squeak 2.3 2 *6 Squeak etoys on Squeak Squeak etoys 3

3 [3] *7 web *8 ( ) 3.1 3 3 1 *9 *7 Interactive Fantasy[4] *8 Critique of games[5] *9 3 1 3 1 4

3.2 GP GP 5 Battle Ship Battle Ship GP Battle Ship 5

3.3 Battle Ship Battle Ship * 10 ( : Battleship) 10 5 4 3 3 2 * 11 3.4 GP Battle Ship GP GP 10 (5 ) (4 ) (3 ) (3 ) (2 ) 1 1 *10 3 *11 6

4 3 3 Practice Verification Score GP Verification Score Battle Ship shoot CUI 7

4.1 Practice GP GP Battle Ship Practice 1 1 Practice 8

4.2 Verification GP Verification 2 2 Verification 9

4.3 Score GP shoot 100 Score 3 3 Score 10

5 GP 4 1. 2. 3. 4. 1 GP 2 3 4 Score 11

5.1 1. 2. 2 12

OB fken [1],,. java. NII, 2006. [2],,,. :. NII, 2008. [3] Marc Prensky. :., 2009. [4] Greg Costikyan. Interactive fantasy. http://www.costik.com/nowords.html, 1994. [5] INOUE Akito.. http://www.critiqueofgames.net/data/index.php?%a5%b2%a1%bc%a5 %E0%A4%CE%C4%EA%B5%C1%CF%C0, 10 2008. URL 2010 1 16 13

A A.1 Practice Prctice A.1.1 senkanplay.c /************************************************************************ * Battle Ship * * - Practice * ************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <time.h> char line[100]; #define N 0 /* */ #define BM 1 /* */ #define BH 2 /* */ #define SK 11 /* : Life 5 */ #define JK 12 /* : Life 4 */ #define KK 13 /* : Life 3 */ #define SM 14 /* : Life 2 */ #define YS 15 /* : Life 2 */ void haichi (int sb[][10]); void dispsb (int sb[][10]); int zanteki (int skp, int jkp, int kkp, int smp, int ysp); void shoot (int sb[][10], int i, int *x, int *y); int meichup (int sb[][10], int x, int y); void meichud (int k); /************************************************************************ * : * * skp => SK * * jkp => JK * * kkp => KK * * smp => SM * * ysp => YS * * * 14

* Life point. * ************************************************************************/ int skp = 5, jkp = 4, kkp = 3, smp = 3, ysp = 2; /************************************************************************ * : * * flg => * * i => * * x => * * y => * * k => * ************************************************************************/ int main (void) int sb[10][10]; static int flg[10][10]=0; int i, x, y, k; haichi (sb); /* */ dispsb (sb); /* Battle Ship */ zanteki (skp, jkp, kkp, smp, ysp); /* */ do shoot (sb, 1, &x, &y); /* */ while(x < 0 x > 9 y < 0 y > 9); /*, */ flg[x][y] = 1; printf ("(x,y) = (%d,%d)\n", x, y); /* */ /********************************************************************** * : * *, 1. * * * * for : * *, 100. * **********************************************************************/ for (i = 2; i <= 100; i++) 15

k = meichup (sb, x, y); dispsb (sb); meichud (k); break; if (zanteki (skp, jkp, kkp, smp, ysp)) /* 0 */ do shoot (sb, i, &x, &y); while((x < 0 x > 9 y < 0 y > 9) flg[x][y]); /*,. */ flg[x][y] = 1; /*. */ printf (" %d\n", --i); /* Battle Ship. */ printf ("\npress any key to continue...\n"); getchar (); /************************************************************************ * haichi : * ************************************************************************/ void haichi (int sb[][10]) int i, j, x, y; srand ((unsigned int) time (NULL)); /* */ for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) 16

sb[i][j] = N; if (rand () % 2 == 0) /* */ x = rand () % 6; sb[x][y] = SK; sb[x + 1][y] = SK; sb[x + 2][y] = SK; sb[x + 3][y] = SK; sb[x + 4][y] = SK; else /* */ y = rand () % 6; sb[x][y] = SK; sb[x][y + 1] = SK; sb[x][y + 2] = SK; sb[x][y + 3] = SK; sb[x][y + 4] = SK; if (rand () % 2 == 0) /* */ x = rand () % 7; while (sb[x][y]!= N sb[x + 1][y]!= N sb[x + 2][y]!= N sb[x + 3][y]!= N) x = rand () % 7; /*,. */ sb[x][y] = JK; sb[x + 1][y] = JK; sb[x + 2][y] = JK; sb[x + 3][y] = JK; else 17

/* */ y = rand () % 7; while (sb[x][y]!= N sb[x][y + 1]!= N sb[x][y + 2]!= N sb[x][y + 3]!= N) y = rand () % 7; /*,. */ sb[x][y] = JK; sb[x][y + 1] = JK; sb[x][y + 2] = JK; sb[x][y + 3] = JK; if (rand () % 2 == 0) /* */ x = rand () % 8; while (sb[x][y]!= N sb[x + 1][y]!= N sb[x + 2][y]!= N) x = rand () % 8; /*,. */ sb[x][y] = KK; sb[x + 1][y] = KK; sb[x + 2][y] = KK; else /* */ y = rand () % 8; while (sb[x][y]!= N sb[x][y + 1]!= N sb[x][y + 2]!= N) y = rand () % 8; /*,. */ 18

sb[x][y] = KK; sb[x][y + 1] = KK; sb[x][y + 2] = KK; if (rand () % 2 == 0) /* */ x = rand () % 8; while (sb[x][y]!= N sb[x + 1][y]!= N sb[x + 2][y]!= N) x = rand () % 8; /*,. */ sb[x][y] = SM; sb[x + 1][y] = SM; sb[x + 2][y] = SM; else /* */ y = rand () % 8; while (sb[x][y]!= N sb[x][y + 1]!= N sb[x][y + 2]!= N) y = rand () % 8; /*,. */ sb[x][y] = SM; sb[x][y + 1] = SM; sb[x][y + 2] = SM; if (rand () % 2 == 0) /* */ x = rand () % 9; while (sb[x][y]!= N sb[x + 1][y]!= N) 19

x = rand () % 9; /*,. */ sb[x][y] = YS; sb[x + 1][y] = YS; else /* */ y = rand () % 9; while (sb[x][y]!= N sb[x][y + 1]!= N) y = rand () % 9; /*,. */ sb[x][y] = YS; sb[x][y + 1] = YS; /*********************************************************************** * dispsb : Battle Ship * * count => * * csb => * ***********************************************************************/ void dispsb (int sb[][10]) int i, j; static int count=0, csb[10][10]; if (!count) /* */ for(i = 0; i < 10; i++) for(j = 0; j < 10; j++) csb[i][j] = sb[i][j]; 20

count = 1; printf (" 1 2 3 4 5 6 7 8 9 10\n"); /* */ printf (" ---------------------\n"); /* : */ for (i = 0; i < 10; i++) printf ("%2d", i + 1); /* */ for (j = 0; j < 10; j++) putchar ( ); /* : */ switch (sb[i][j]) /* */ case BM: /* */ switch (csb[i][j]) case SK: /* */ /***************************************************** *, * * 5. * *****************************************************/ if (!skp) putchar( 5 ); /***************************************************** *, 1 * *. * *****************************************************/ else putchar( 1 ); break; case JK: /* */ /***************************************************** 21

*, * * 4. * *****************************************************/ if (!jkp) putchar( 4 ); /***************************************************** *, 1 * *. * *****************************************************/ else putchar( 1 ); break; case SM: /* */ /***************************************************** *, * * 3. * *****************************************************/ if (!smp) putchar( 3 ); /***************************************************** *, 1 * *. * *****************************************************/ else putchar( 1 ); break; case KK: /* */ /***************************************************** *, * 22

* 3. * *****************************************************/ if (!kkp) putchar( 3 ); /***************************************************** *, 1 * *. * *****************************************************/ else putchar( 1 ); break; case YS: /* */ /***************************************************** *, * * 2. * *****************************************************/ if (!ysp) putchar( 2 ); /***************************************************** *, 1 * *. * *****************************************************/ else putchar( 1 ); break; case BH: /* */ putchar ( X ); break; 23

default: /* */ putchar ( ); break; printf (" \n"); /* : */ printf (" ---------------------\n"); /* : */ /********************************************************************** * zanteki : * **********************************************************************/ int zanteki (int skp, int jkp, int kkp, int smp, int ysp) if (skp == 0 && jkp == 0 && kkp == 0 && smp == 0 && ysp == 0) printf (" \n"); return 1; printf (" "); if (skp > 0) printf (" "); if (jkp > 0) printf (" "); if (kkp > 0) printf (" "); if (smp > 0) printf (" "); if (ysp > 0) 24

printf (" "); putchar ( \n ); return 0; void shoot (int sb[][10], int i, int *x, int *y) int tate, yoko; while (1) printf (" (%d), ", i); fgets (line, sizeof (line), stdin); sscanf (line, "%d,%d", &tate, &yoko); // if (tate >= 1 && tate <= 10 && yoko >= 1 && yoko <= 10) // *x = tate - 1; *y = yoko - 1; return; // int meichup (int sb[][10], int x, int y) int a; a = sb[x][y]; if (a == SK) sb[x][y] = BM; skp--; return SK; if (a == JK) sb[x][y] = BM; jkp--; 25

return JK; if (a == KK) sb[x][y] = BM; kkp--; return KK; if (a == SM) sb[x][y] = BM; smp--; return SM; if (a == YS) sb[x][y] = BM; ysp--; return YS; if (a == BM) return BH; sb[x][y] = BH; return BH; void meichud (int k) if (k == BH) printf (" \n"); else if (k == SK) printf (" "); if (skp <= 0) printf (" "); putchar ( \n ); 26

else if (k == JK) printf (" "); if (jkp <= 0) printf (" "); putchar ( \n ); else if (k == KK) printf (" "); if (kkp <= 0) printf (" "); putchar ( \n ); else if (k == SM) printf (" "); if (smp <= 0) printf (" "); putchar ( \n ); else if (k == YS) printf (" "); if (ysp <= 0) printf (" "); putchar ( \n ); 27

A.2 Verification Verification A.2.1 senkan001.c #include <stdio.h> #include <stdlib.h> #include <time.h> char line[100]; #define N 0 #define BM 1 #define BH 2 #define SK 11 #define JK 12 #define KK 13 #define SM 14 #define YS 15 void haichi (int sb[][10]); void dispsb (int tsb[][10], int sb[][10]); int zanteki (int skp, int jkp, int kkp, int smp, int ysp); void shoot (int sb[][10], int i, int k, int *x, int *y); int meichup (int tsb[][10], int sb[][10], int x, int y); int meichud (int k); int skp = 5, jkp = 4, kkp = 3, smp = 3, ysp = 2; int main (void) int tsb[10][10], sb[10][10]; static int flg[10][10]=0; int i, j, x, y, k, kekka; haichi (tsb); for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) 28

sb[i][j] = N; dispsb (tsb, sb); zanteki (skp, jkp, kkp, smp, ysp); do shoot (sb, 1, BH, &x, &y); getchar (); while(x < 0 x > 9 y < 0 y > 9); for (i = 2; i <= 100; i++) k = meichup (tsb, sb, x, y); dispsb (tsb, sb); kekka = meichud (k); if (zanteki (skp, jkp, kkp, smp, ysp)) break; do shoot (sb, i, kekka, &x, &y); getchar (); while((x < 0 x > 9 y < 0 y > 9) flg[x][y]); flg[x][y] = 1; printf (" %d\n", --i); printf ("Press any key to continue...\n"); getchar (); void haichi (int sb[][10]) 29

int i, j, x, y; srand ((unsigned int) time (NULL)); for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) sb[i][j] = N; if (rand () % 2 == 0) /* */ x = rand () % 6; sb[x][y] = SK; sb[x + 1][y] = SK; sb[x + 2][y] = SK; sb[x + 3][y] = SK; sb[x + 4][y] = SK; else /* */ y = rand () % 6; sb[x][y] = SK; sb[x][y + 1] = SK; sb[x][y + 2] = SK; sb[x][y + 3] = SK; sb[x][y + 4] = SK; if (rand () % 2 == 0) /* */ x = rand () % 7; while (sb[x][y]!= N sb[x + 1][y]!= N sb[x + 2][y]!= N sb[x + 3][y]!= N) x = rand () % 7; 30

sb[x][y] = JK; sb[x + 1][y] = JK; sb[x + 2][y] = JK; sb[x + 3][y] = JK; else /* */ y = rand () % 7; while (sb[x][y]!= N sb[x][y + 1]!= N sb[x][y + 2]!= N sb[x][y + 3]!= N) y = rand () % 7; sb[x][y] = JK; sb[x][y + 1] = JK; sb[x][y + 2] = JK; sb[x][y + 3] = JK; if (rand () % 2 == 0) /* */ x = rand () % 8; while (sb[x][y]!= N sb[x + 1][y]!= N sb[x + 2][y]!= N) x = rand () % 8; sb[x][y] = KK; sb[x + 1][y] = KK; sb[x + 2][y] = KK; else /* */ y = rand () % 8; while (sb[x][y]!= N sb[x][y + 1]!= N sb[x][y + 2]!= N) y = rand () % 8; 31

sb[x][y] = KK; sb[x][y + 1] = KK; sb[x][y + 2] = KK; if (rand () % 2 == 0) /* */ x = rand () % 8; while (sb[x][y]!= N sb[x + 1][y]!= N sb[x + 2][y]!= N) x = rand () % 8; sb[x][y] = SM; sb[x + 1][y] = SM; sb[x + 2][y] = SM; else /* */ y = rand () % 8; while (sb[x][y]!= N sb[x][y + 1]!= N sb[x][y + 2]!= N) y = rand () % 8; sb[x][y] = SM; sb[x][y + 1] = SM; sb[x][y + 2] = SM; if (rand () % 2 == 0) /* */ x = rand () % 9; while (sb[x][y]!= N sb[x + 1][y]!= N) x = rand () % 9; sb[x][y] = YS; sb[x + 1][y] = YS; 32

else /* */ y = rand () % 9; while (sb[x][y]!= N sb[x][y + 1]!= N) y = rand () % 9; sb[x][y] = YS; sb[x][y + 1] = YS; void dispsb (int tsb[][10], int sb[][10]) int i, j; printf (" printf (" 1 2 3 4 5 6 7 8 9 10\n"); ---------------------\n"); for (i = 0; i < 10; i++) printf ("%2d", i + 1); for (j = 0; j < 10; j++) putchar ( ); switch (sb[i][j]) /* */ case BM: switch (tsb[i][j]) case SK: if (!skp) putchar( 5 ); else putchar( 1 ); 33

break; case JK: if (!jkp) putchar( 4 ); else putchar( 1 ); break; case SM: if (!smp) putchar( 3 ); else putchar( 1 ); break; case KK: if (!kkp) putchar( 3 ); else putchar( 1 ); break; case YS: if (!ysp) putchar( 2 ); else putchar( 1 ); break; case BH: 34

putchar ( X ); break; default: putchar ( ); break; printf (" \n"); printf (" ---------------------\n"); int zanteki (int skp, int jkp, int kkp, int smp, int ysp) if (skp <= 0 && jkp <= 0 && kkp <= 0 && smp <= 0 && ysp <= 0) printf (" \n"); return 1; printf (" "); if (skp > 0) printf (" "); if (jkp > 0) printf (" "); if (kkp > 0) printf (" "); if (smp > 0) printf (" "); if (ysp > 0) printf (" "); putchar ( \n ); 35

return 0; int meichup (int tsb[][10], int sb[][10], int x, int y) int a, b; a = tsb[x][y]; b = sb[x][y]; if (b!= N) return BH; if (a == SK) sb[x][y] = BM; skp--; return SK; if (a == JK) sb[x][y] = BM; jkp--; return JK; if (a == KK) sb[x][y] = BM; kkp--; return KK; if (a == SM) sb[x][y] = BM; smp--; return SM; if (a == YS) sb[x][y] = BM; 36

ysp--; return YS; sb[x][y] = BH; return BH; int meichud (int k) if (k == BH) printf (" \n"); return BH; else if (k == SK) printf (" "); if (skp <= 0) printf (" \n"); return SK; putchar ( \n ); else if (k == JK) printf (" "); if (jkp <= 0) printf (" \n"); return JK; putchar ( \n ); else if (k == KK) printf (" "); if (kkp <= 0) printf (" \n"); return KK; 37

putchar ( \n ); else if (k == SM) printf (" "); if (smp <= 0) printf (" \n"); return SM; putchar ( \n ); else if (k == YS) printf (" "); if (ysp <= 0) printf (" \n"); return YS; putchar ( \n ); return BM; 38

A.3 Score Score A.3.1 senkan100.c #include <stdio.h> #include <stdlib.h> #include <time.h> char line[100]; #define N 0 #define BM 1 #define BH 2 #define SK 11 #define JK 12 #define KK 13 #define SM 14 #define YS 15 void haichi (int sb[][10]); void dispsb (int sb[][10]); int zanteki (int skp, int jkp, int kkp, int smp, int ysp); void shoot (int sb[][10], int i, int k, int *x, int *y); int meichup (int tsb[][10], int sb[][10], int x, int y); int meichud (int k); int skp = 5, jkp = 4, kkp = 3, smp = 3, ysp = 2; int main (void) int tsb[10][10], sb[10][10]; static int flg[10][10]=0; int i, j, a, b, x, y, k, kekka, total = 0; for (j = 1; j <= 100; j++) skp = 5, jkp = 4, kkp = 3, smp = 3, ysp = 2; haichi (tsb); 39

for (a = 0; a < 10; a++) for (b = 0; b < 10; b++) sb[a][b] = N; zanteki (skp, jkp, kkp, smp, ysp); do shoot (sb, 1, BH, &x, &y); while((x < 0 x > 9 y < 0 y > 9) flg[x][y]); for (i = 2; i <= 100; i++) k = meichup (tsb, sb, x, y); kekka = meichud (k); if (zanteki (skp, jkp, kkp, smp, ysp)) break; do shoot (sb, i, kekka, &x, &y); while((x < 0 x > 9 y < 0 y > 9) flg[x][y]); flg[x][y] = 1; for (a = 0; a < 10; a++) for (b = 0; b < 10; b++) flg[a][b] = 0; 40

i--; total = total + i; printf ("%3d %3d \n", j, i); printf (" %6.2f\n", total / 100.0); void haichi (int sb[][10]) int i, j, x, y; static unsigned int seed = 1; srand ((unsigned int) time (NULL) * seed); for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) sb[i][j] = N; if (rand () % 2 == 0) /* */ x = rand () % 6; sb[x][y] = SK; sb[x + 1][y] = SK; sb[x + 2][y] = SK; sb[x + 3][y] = SK; sb[x + 4][y] = SK; else /* */ y = rand () % 6; sb[x][y] = SK; sb[x][y + 1] = SK; sb[x][y + 2] = SK; sb[x][y + 3] = SK; sb[x][y + 4] = SK; 41

if (rand () % 2 == 0) /* */ x = rand () % 7; while (sb[x][y]!= N sb[x + 1][y]!= N sb[x + 2][y]!= N sb[x + 3][y]!= N) x = rand () % 7; sb[x][y] = JK; sb[x + 1][y] = JK; sb[x + 2][y] = JK; sb[x + 3][y] = JK; else /* */ y = rand () % 7; while (sb[x][y]!= N sb[x][y + 1]!= N sb[x][y + 2]!= N sb[x][y + 3]!= N) y = rand () % 7; sb[x][y] = JK; sb[x][y + 1] = JK; sb[x][y + 2] = JK; sb[x][y + 3] = JK; if (rand () % 2 == 0) /* */ x = rand () % 8; while (sb[x][y]!= N sb[x + 1][y]!= N sb[x + 2][y]!= N) x = rand () % 8; sb[x][y] = KK; 42

sb[x + 1][y] = KK; sb[x + 2][y] = KK; else /* */ y = rand () % 8; while (sb[x][y]!= N sb[x][y + 1]!= N sb[x][y + 2]!= N) y = rand () % 8; sb[x][y] = KK; sb[x][y + 1] = KK; sb[x][y + 2] = KK; if (rand () % 2 == 0) /* */ x = rand () % 8; while (sb[x][y]!= N sb[x + 1][y]!= N sb[x + 2][y]!= N) x = rand () % 8; sb[x][y] = SM; sb[x + 1][y] = SM; sb[x + 2][y] = SM; else /* */ y = rand () % 8; while (sb[x][y]!= N sb[x][y + 1]!= N sb[x][y + 2]!= N) y = rand () % 8; sb[x][y] = SM; sb[x][y + 1] = SM; sb[x][y + 2] = SM; 43

if (rand () % 2 == 0) /* */ x = rand () % 9; while (sb[x][y]!= N sb[x + 1][y]!= N) x = rand () % 9; sb[x][y] = YS; sb[x + 1][y] = YS; else /* */ y = rand () % 9; while (sb[x][y]!= N sb[x][y + 1]!= N) y = rand () % 9; sb[x][y] = YS; sb[x][y + 1] = YS; seed = rand (); void dispsb (int sb[][10]) int i, j; printf (" printf (" 1 2 3 4 5 6 7 8 9 10\n"); ---------------------\n"); for (i = 0; i < 10; i++) printf ("%2d", i + 1); for (j = 0; j < 10; j++) putchar ( ); switch (sb[i][j]) 44

case BM: putchar ( O ); break; case BH: putchar ( X ); break; default: putchar ( ); break; printf (" \n"); printf (" ---------------------\n"); int zanteki (int skp, int jkp, int kkp, int smp, int ysp) if (skp <= 0 && jkp <= 0 && kkp <= 0 && smp <= 0 && ysp <= 0) /* printf(" \n"); */ return 1; /* printf(" "); if(skp > 0) printf(" "); if(jkp > 0) printf(" "); if(kkp > 0) printf(" "); if(smp > 0) printf(" "); if(ysp > 0) printf(" "); 45

putchar( \n ); */ return 0; int meichup (int tsb[][10], int sb[][10], int x, int y) int a, b; a = tsb[x][y]; b = sb[x][y]; if (b!= N) return BH; if (a == SK) sb[x][y] = BM; skp--; return SK; if (a == JK) sb[x][y] = BM; jkp--; return JK; if (a == KK) sb[x][y] = BM; kkp--; return KK; if (a == SM) sb[x][y] = BM; smp--; return SM; if (a == YS) 46

sb[x][y] = BM; ysp--; return YS; sb[x][y] = BH; return BH; int meichud (int k) if (k == BH) return BH; else if (k == SK && skp <= 0) return SK; else if (k == JK && jkp <= 0) return JK; else if (k == KK && kkp <= 0) return KK; else if (k == SM && smp <= 0) return SM; else if (k == YS && ysp <= 0) return YS; return BM; 47