/*****************************************/
/****************棋子的走法***************/
/*****************************************/
function check(chess, from, to){
	/****************************[卒]*******************************/
	if(chess == "011" || chess == "012" || chess == "013" || chess == "014" || chess == "015"){			//控制黑旗卒的走法
		if(from >= 46 && (from - to == 1 || to - from == 1))
		return 1;				//横向走
		if(to - from == 9)		//卒字必须向前走，因此它的目的坐标减去走前的坐标必须等于9，说明走的是直线
		return 1;				//向前走一步
	}
	if(chess == "111" || chess == "112" || chess == "113" || chess == "114" || chess == "115"){			//控制黑旗卒的走法
		if(from <= 45 && (from - to == 1 || to - from == 1))
		return 1;			//横向走
		if(from - to == 9)	//卒字必须向前走，因此它的原点坐标减去目的坐标必须等于9，说明走的是直线
		return 1;			//向前走一步
	}

	/*****************************[炮]******************************/
	if(chess == "010" || chess == "009" || chess == "110" || chess == "109"){			//控制炮的走法
		if(to - from > 0 && (to - from) % 9 == 0){				//控制炮向下走
			var count = 0;
			for(var i = from + 9;i < to;i += 9){
				if(document.getElementById("chess_value_"+i).value != "blank")
				count ++;
			}
			if(count == 0 && document.getElementById("chess_value_"+to).value == "blank")			//炮前不允许有旗子时，可以走棋
			return 1;
			if(count == 1 && document.getElementById("chess_value_"+to).value != "blank")			//炮前面有一个旗子时，可以走棋
			return 1;
		}
		if(from - to > 0 && (from - to) % 9 == 0){			//控制炮向上走
			var count = 0;
			for(var i = to + 9;i < from;i += 9){
				if(document.getElementById("chess_value_"+i).value != "blank")
				count ++;
			}
			if(count == 0 && document.getElementById("chess_value_"+to).value == "blank")
			return 1;
			if(count == 1 && document.getElementById("chess_value_"+to).value != "blank")
			return 1;
		}
		if(to - from > 0 && to - from < 9){			//控制炮向右走
			var count = 0;
			for(var i = from + 1;i < to;i ++){
				if(document.getElementById("chess_value_"+i).value != "blank")
				count ++;
			}
			if(count == 0 && document.getElementById("chess_value_"+to).value == "blank")
			return 1;
			if(count == 1 && document.getElementById("chess_value_"+to).value != "blank")
			return 1;
		}
		if(from - to > 0 && from - to < 9){			//控制炮向左走
			var count = 0;
			for(var i = to + 1;i < from;i ++)
			{
				if(document.getElementById("chess_value_"+i).value != "blank")
				count ++;
			}
			if(count == 0 && document.getElementById("chess_value_"+to).value == "blank")
			return 1;
			if(count == 1 && document.getElementById("chess_value_"+to).value != "blank")
			return 1;
		}
	}
	/****************************[车]*******************************/
	if(chess == "008" || chess == "007" || chess == "108" || chess == "107"){		//控制车的走法
		if(to - from > 0 && (to - from) % 9 == 0){			//控制车向上走
			var count = 0;
			for(var i = from + 9;i < to;i += 9){
				if(document.getElementById("chess_value_"+i).value != "blank")
				count ++;
			}
			if(count == 0)
			return 1;
		}
		if(from - to > 0 && (from - to) % 9 == 0){			//控制车向下走
			var count = 0;
			for(var i = to + 9;i < from;i += 9)
			{
				if(document.getElementById("chess_value_"+i).value != "blank")
				count ++;
			}
			if(count == 0)
			return 1;
		}
		if(to - from > 0 && to - from < 9){			//控制车向右走
			var count = 0;
			for(var i = from + 1;i < to;i ++)
			{
				if(document.getElementById("chess_value_"+i).value != "blank")
				count ++;
			}
			if(count == 0)
			return 1;
		}
		if(from - to > 0 && from - to < 9){			//控制车向左走
			var count = 0;
			for(var i = to + 1;i < from;i ++){
				if(document.getElementById("chess_value_"+i).value != "blank")
				count ++;
			}
			if(count == 0)
			return 1;
		}
	}
	/*****************************[马]******************************/
	if(chess == "006" || chess == "005" || chess == "106" || chess == "105"){		//控制马的走法
		if(to - from == 19 || to - from == 17){			//控制马向上走“日”字（向前上17或19个坐标点），并且马所在坐标点的直上方必须是空棋
			if(document.getElementById("chess_value_"+(from + 9)).value == "blank")
			return 1;
		}
		if(from - to == 19|| from - to == 17){			//控制马向下走“日”字（向下走17或19个坐标点），并且马所在坐标点的直下方必须是空棋
			if(document.getElementById("chess_value_"+(from - 9)).value == "blank")
			return 1;
		}
		if(to - from == 7 || from - to == 11){					//控制向左走横“日”字（向左上角和左下角走7或11个坐标点）
			if(document.getElementById("chess_value_"+(from - 1)).value == "blank")			//马所在坐标点减1必须是空棋
			return 1;
		}
		if(from - to == 7 || to - from == 11){					//控制向右走横“日”字（向下走7和11个坐标点）
			if(document.getElementById("chess_value_"+(from + 1)).value == "blank")			//马所在坐标点+1必须是空棋
			return 1;
		}
	}
	/****************************[象]******************************/
	if(((chess == "004" || chess == "003") && to <= 45) || ((chess == "104" || chess == "103") && to >= 46)){		//控制象的走法
		if(to - from == 16){			//控制象向左下走
			if(document.getElementById("chess_value_"+(from + 8)).value == "blank")		//该棋子当前坐标点加8必须是空棋，田字的心必须是空棋，不能超过16个坐标点区域
			return 1;
		}
		if(from - to == 16){			//控制象向右上走
			if(document.getElementById("chess_value_"+(from - 8)).value == "blank")		//该棋子当前坐标点减8必须是空棋，田字的心必须是空棋，不能超过16个坐标点区域
			return 1;
		}
		if(to - from ==20){			//控制象向右下走
			if(document.getElementById("chess_value_"+(from + 10)).value == "blank")	//该棋子当前坐标点加10必须是空棋，田字的心必须是空棋，不能超过20个坐标点区域
			return 1;
		}
		if(from - to == 20){			//控制象向左上走
			if(document.getElementById("chess_value_"+(from - 10)).value == "blank")	//该棋子当前坐标点减10必须是空棋，田字的心必须是空棋，不能超过20个坐标点区域
			return 1;
		}
	}
	/****************************[士]*****************************/
	if(chess == "002" || chess == "001"){		//控制黑旗士的走法(所走范围在4、6、14、22、24点)，不能超过8个或10个坐标点
		if((to == 6 || to == 4 || to == 14 || to == 22 || to == 24) && (to - from == 8 || from - to == 8 || to - from == 10 || from - to == 10))
		return 1;
	}
	if(chess == "102" || chess == "101"){		//控制红旗士的走法
		if((to == 85 || to == 87 || to == 77 || to == 69 || to == 67) && (to - from == 8 || from - to == 8 || to - from == 10 || from - to == 10))
		return 1;
	}

	/****************************[将]*****************************/
	if(chess == "000"){			//控制黑旗将的走法
		if(((to >= 4 && to <= 6) || (to >= 13 && to <= 15) || (to >= 22 && to <= 24)) && (to - from == 1 || from - to == 1 || to - from == 9 || from - to == 9))
		return 1;
		if(to > from && (to - from) % 9 == 0 && document.getElementById("chess_value_"+to).value == "100"){
			var count = 0;
			for(var i = from + 9;i < to;i += 9){		//该棋子所对应的直上方或直下方如果不为空，则Count变量加1，说明有棋，不能走，系统会弹出提示
				if(document.getElementById("chess_value_"+i).value != "blank")
				count ++;
			}
			if(count == 0)			//如果count变量值为0，则说明可以行走
			return 1;
		}
	}
	if(chess == "100"){			//控制红旗将的走法(所走范围在85、86、87、76、77、78、67、68、69点)
		if(((to <= 87 && to >= 85) || (to <= 78 && to >=76) || (to <= 69 && to >= 67)) && (to - from == 1 || from - to == 1 || to - from == 9 || from - to == 9))		return 1;
		if(from > to && (from - to) % 9 == 0 && document.getElementById("chess_value_"+to).value == "000"){
			var count = 0;
			for(var i = to + 9;i < from;i += 9){	//该棋子所对应的直上方或直下方如果不为空，则Count变量加1，说明有棋，不能走，系统会弹出提示
				if(document.getElementById("chess_value_"+i).value != "blank")		
				count ++;
			}
			if(count == 0)			//如果count变量值为0，则说明可以行走
			return 1;
		}
	}
	return 0;
}