Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ryuichimatsumoto-single/2329854 to your computer and use it in GitHub Desktop.
Save ryuichimatsumoto-single/2329854 to your computer and use it in GitHub Desktop.
○× games
#define board_size 5
#include<stdio.h>
main()
{
int board[board_size][board_size];
int i;
for(i= 0;i<board_size;i++)
{
board[i][j] = 0;//initlizing board
}
}
/*
*@NOTICE:SORRY,THIS CODE CANNOT WORK!
*@author Ryuichi Matsumoto
*@date 2012.4.8
*/
function alternative_board(size)
{
this.row = size
this.col = size;
this.board[row][col];
for(var i=0;i<size;i++)
{
for(var j=0;j<size;j++)
{
this.board[i][j] = 0;//ボードの初期化
}
}
/*
*ボードに○×を付ける(write ○ or × on board)
*/
this.putboard = function(row,col,player)
{
this.board[row][col] = player;
}
/*
*ボードの判定
*/
this.checkboard = function(player)
{
/*縦の判定*/
var check_row = 0;//縦の判定フラグ
var check_col = 0;//横の判定フラグ
var check_quater1 = 0;//斜め(1)のフラグ
var check_quater2 = 0;//斜め(2)のフラグ
/*横の判定*/
for(var i=0;i<this.row;i++)
{
check_row = 0;//判定に入る前に初期化
for(var j=0;j<this.col;j++)
{
if(this.board[i][j] == player)
{
check_row++;
}
}
if(check_row == this.row)
{
return 1;
}
}
/*縦の判定*/
for(var i=0;i<this.row;i++)
{
check_col = 0;//判定に入る前に初期化
for(var j=0;j<this.col;j++)
{
if(this.board[j][i] == player)
{
check_col++;
}
}
if(check_col == this.col)
{
return 1;
}
}
/*斜めの判定(1)*/
for(var i=0;i<this.row;i++)
{
if(this.board[i][i] == player)
{
check_quater1++;
}
}
if(check_quater1 == this.col)
{
return 1;
}
}
/*斜めの判定(2)*/
for(var i=0;i<this.row;i++)
{
if(this.board[this.row - i][i] == player)
{
check_quater2++;
}
}
if(check_quater2 == this.col)
{
return 1;
}
}
}
}
<html>
<script type="text/javascript">
/*
*alternative_board:ボードを定義するクラス
*@row:縦,col:横
*@this.board:○×の判定 0:何も置かれていない(default) 1:player1(○) 2:player2(×)
*@author Ryuichi Matsumoto
*@date 2012.4.8
*/
function alternative_board()
{
this.board =[['0','0','0','0','0'],['0','0','0','0','0'],['0','0','0','0','0'],['0','0','0','0','0'],['0','0','0','0','0']] ;
}
var Board = new alternative_board();
</script>
</html>
@Aventador-Java
Copy link

it does not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment