- 1 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:43:38.579 ID:i97ZSxBK0
- #include <stdio.h>
#include <windows.h>#define WALL -1
#define SPACE -1
#define WHITE 0
#define BLACK 1
#define TRUE 1
#define FALSE 0
#define null -1typedef struct{int row;int column;}player;
int Board[10][10];int Copy[8][8];int disp[2][8] = {{-1,-1,0,1,1,1,0,-1},{0,1,1,1,0,-1,-1,-1}};
int direction[2][6] = {{null,null,null,null,null,null},{null,null,null,null,null,null}};
int you_piece = 2, com_piece = 2, OseroCount = 60, success;
int max, e_max, expect, result, e_result;int you = 2, playercounter = 1;player players[2];void BoardPrint(void);void BoardCopy(int);
void Format(void);void TableFormat(int, int, int[], int);
void Add(int, int);void Change(int, int, int, int, int);
void Computer(int, int);void Simulation(int, int, int, int[]);
void EnemySearch(int, int, int, int);int Move(int, int, int, int, int);続く
- 2 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:44:23.901 ID:i97ZSxBK0
- void BoardPrint(void){
int i, j;printf("—————————————–\n");
for(i = 1; i <= 8; i++){printf("|");for(j = 1; j <= 8; j++){
switch(Board[i][j]){
case SPACE: printf(" "); break;
case WHITE: printf(" ●"); break;
case BLACK: printf(" ○"); break;}
printf(" |");}printf("\n—————————————–\n");
}printf("あなた %d コンピューター %d 残り枚数 %d",you_piece, com_piece, OseroCount);printf("\n\n\n");}void BoardCopy(int stat){int i, j;
switch(stat){
case 1:{
for(i = 0; i < 8; i++){for(j = 0; j < 8; j++)Copy[i][j] = Board[i + 1][j + 1];}
}break;
case 2:{
for(i = 0; i < 8; i++){for(j = 0; j < 8; j++)
Board[i + 1][j + 1] = Copy[i][j];}break;
}}}void Format(void){
int i, j;
for(i = 0; i < 10; i++){for(j = 0; j < 10; j++){
if(i == 0 || i == 9)Board[i][j] = WALL;
else if(j == 0 || j == 9)Board[i][j] = WALL;
else Board[i][j] = SPACE;}}
Board[4][4] = WHITE;Board[4][5] = BLACK;
Board[5][4] = BLACK;Board[5][5] = WHITE;
BoardPrint();}続く
- 3 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:44:47.299 ID:LjkOXgc/r
- コンパイルして
- 4 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:45:44.997 ID:i97ZSxBK0
- void TableFormat(int y, int x, int Table[], int player){
int idx;
players[player].row = y;players[player].column = x;
for(idx = 0; direction[player][idx] != null; idx++)direction[player][idx] = null;
for(idx = 0; Table[idx] != null; idx++)direction[player][idx] = Table[idx];}void Add(int cnt, int stat){
if(stat == 1){if(expect == TRUE)result -= cnt;
else result = com_piece + cnt;}
else{if(playercounter == you){
you_piece += cnt;com_piece -= cnt;}
else{com_piece += cnt;you_piece -= cnt;}}}void Change(int y, int x, int d, int player, int stat){
int cnt;
for(cnt = 1; Board[y + cnt * disp[0][d]][x + cnt * disp[1][d]] != player; cnt++)
Board[y + cnt * disp[0][d]][x + cnt * disp[1][d]] = player;
if(stat == 1)Add(cnt – 1, 1);
else Add(cnt – 1, 2);}int Move(int y, int x, int d, int player, int enemy){
int cnt;
for(cnt = 1; Board[y + cnt * disp[0][d]][x + cnt * disp[1][d]] == enemy; cnt++);
if(Board[y + cnt * disp[0][d]][x + cnt * disp[1][d]] == player){
if(expect == TRUE)e_result = e_result + cnt;return TRUE;}
else return FALSE;}続く
- 5 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:45:50.630 ID:YaVgQ7F2d
- 永井産業
- 6 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:46:07.677 ID:g7+jZlrC0
- なるほど完全に理解したわ(´・ω・`)
- 7 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:46:30.758 ID:ZWk/wQ8v0
- こいつ一体何が目的なんだ・・・?
- 8 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:46:53.188 ID:i97ZSxBK0
- void Simulation(int y, int x, int player, int Table[]){
int idx;
if(expect == TRUE){if(e_max <= e_result)e_max = e_result;TableFormat(y, x, Table, player);}
else{Board[y][x] = player;for(idx = 0; Table[idx] != null; idx++)
Change(y, x, Table[idx], player, 1);result++;expect = TRUE;Computer(WHITE, BLACK);
if(max <= result){max = result;TableFormat(y, x, Table, player);}
BoardCopy(2);expect = FALSE;}}void EnemySearch(int y, int x, int player, int enemy){
int i, idx = 0, stat = FALSE;int Table[6] = {null, null, null, null, null, null};
e_result = e_max;
for(i = 0; i < 8; i++){if(Board[y + disp[0][i]][x + disp[1][i]] == enemy){ //隣に敵が居るか
stat = Move(y, x, i, player, enemy);if(stat == TRUE){Table[idx++] = i;}}}
if(Table[0] != null){if(playercounter == you){
for(idx = 0; Table[idx] != null; idx++)Change(y, x, Table[idx], WHITE, 2);success = TRUE;}
else Simulation(y, x, player, Table);}}void Computer(int player, int enemy){
int i, j, idx;
for(i = 1; i <= 8; i++){for(j = 1; j <= 8; j++){
if(Board[i][j] == SPACE) //置ける場所があった
EnemySearch(i, j, player, enemy); //敵を探しにいく
}}
if(expect == TRUE && you_piece < e_max){ //先読みしてるか
Board[players[0].row][players[0].column] = player;
for(idx = 0; direction[0][idx] != null; idx++)
Change(players[0].row, players[0].column, direction[0][idx], player, 1);}}続く
- 9 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:47:49.386 ID:2Ty/MPpS0
- ベーシックマガジンで既に20年以上前に公開されているだろ
- 10 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:47:55.096 ID:i97ZSxBK0
- int main(void){
int row, column, pass, idx;
printf("——————————–オ セ ロ ゲ ー ム——————————-\n\n\n");
Format();
printf("①先攻 ②後攻 : "); scanf("%d",&you);printf("\n\nゲームスタート!\n\n");
printf("——————————————————————————–\n");
while(OseroCount){success = FALSE;
if(playercounter == you){int sw = 1;
while(sw == 1){printf("①パスする ②パスしない : "); scanf("%d",&pass);
if(pass == 1)break;
printf("行 : "); scanf("%d",&row);printf("列 : "); scanf("%d",&column);
EnemySearch(row, column, WHITE, BLACK);if(success == TRUE){Board[row][column] = WHITE;
you_piece++;sw = 0;}
else printf("\nそこには置けません\n");}}
else{BoardCopy(1);max = 0;e_max = you_piece;Computer(BLACK, WHITE);
if(com_piece <= max){Board[players[1].row][players[1].column] = BLACK;
for(idx = 0; direction[1][idx] != null; idx++){
Change(players[1].row, players[1].column, direction[1][idx], BLACK, 2);}
success = TRUE;com_piece++;}
else printf("\n\nパス\n\n");}
if(success == TRUE)OseroCount–;
system("cls");BoardPrint();Sleep(750);playercounter++;
if(playercounter > 2)playercounter = 1;}
printf("——————————————————————————–\n");
printf("ゲーム終了!\n\n");printf("あなた %d コンピューター %d\n\n勝者は",you_piece, com_piece);
if(you_piece > com_piece)printf("あなたです\n\n");
else printf("コンピューターです\n\n");
return 0;}終わり つかれた
- 11 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:48:25.282 ID:zJvO/Jdld
- 難易度変えられるの?
- 13 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:49:55.984 ID:i97ZSxBK0
- >>11
帰れないけどコンピューターには先の先まで読ませる仕様にした はず - 12 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:48:44.431 ID:RNwa8qAW0
- ソリューションごとGitHubにでも上げてくれればレビューしやすいぞ
- 16 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:59:36.956 ID:i97ZSxBK0
- >>12
やろうとしたけど英語の壁が・・・ - 14 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:54:56.684 ID:bBH8AmN80
- 動くか試した?
- 15 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 09:56:35.755 ID:i97ZSxBK0
- >>14
ちゃんとテストゲームしたよ - 17 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:01:13.195 ID:NtpT0Iqga
- ほとんど読んでないけどパスは選択式じゃなくて置けるか判定して自動にしろ
- 19 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:04:42.923 ID:i97ZSxBK0
- >>17
改善に努めます - 18 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:01:39.032 ID:dFPixqU20
- 乙
次はjsでよろしく - 20 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:05:14.680 ID:6a3JEeEI0
- コンソールとかなめてんのか?
- 21 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:06:31.524 ID:GoWbKO++d
- >>20
C言語だし - 22 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:08:27.465 ID:i97ZSxBK0
- よさそうなとこ見つけた
- 29 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:29:26.573 ID:i97ZSxBK0
- >>22で我慢してくれ・・・
- 23 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:11:24.317 ID:i97ZSxBK0
- ちなみに自分の色は●、コンピューターは〇です
- 24 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:11:25.636 ID:WVneQ2nU0
- ソースが汚い
インデント付けろ - 25 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:14:30.971 ID:i97ZSxBK0
- >>24
すまん
行数の制約もあるから無理やり詰めてたもんで・・・ - 26 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:21:58.415 ID:io867Ijr0
- プログラム楽しいよな
- 27 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:24:51.883 ID:i97ZSxBK0
- >>26
楽しい
頭めちゃくちゃ疲れるけど - 28 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:26:51.078 ID:IBmoSy/h0
- Gistに貼って
- 30 名前:番組の途中ですが翡翠の名無しがお送りします 投稿日時:2020/05/14(木) 10:39:28.152 ID:i97ZSxBK0
- 見やすくなったと思う
http://n-h.x0.to/old_pc/up/src/up0118.txt
C言語でオセロゲーム作った

コメント