做了一个Ajax象棋,棋力还可以,一般业余水平的人下不过服务器,大家帮我测试一下.
http://www.dullwolf.cn/Chess/
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SuperDullWolfChess._Default" %>
<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<style>
v/:*
{
behavior: url(#default#VML);
}
body
{
background-color: DarkGoldenrod;
margin-left: 10px;
margin-top: 10px;
}
oval
{
position: absolute;
}
</style>
<script language="javascript" type="text/javascript" src="Ajax.js">
</script>
<script language="javascript" type="text/javascript">
var name = navigator.appName;
if(name!="Microsoft Internet Explorer"){
alert("由于采用了无图片VML技术,所以请使用IE浏览器访问本页");
}
var chessObj;
var myColor="red";
var enemyColor="gray";
var qiNum=32;//棋子数量
var qID="";
var qName="";
var xx=0;//起点坐标
var yy=0;
var xxx=0;//终点坐标
var yyy=0;
var step=0;
var eatNum=0;
var eatNumRed=0;
var whosTurn="w";
//显示中国棋谱的数组
var moveChineseArray=new Array();
//用来判断长将长捉的历史步数
var moveArray=new Array();
//用来回退棋子的数组。
var RetractArray=new Array();
//悔棋
//悔棋时候走的棋
//*******以下是选择棋子和目标部分**********
function sel(obj){
//如果手中无棋,选中棋子,否则确定目标点
if(obj.fillColor != myColor ) {
return;
}
// if(qID!="" && qID!=obj.id){
// target();
// }
//selectNull();
if(obj.strokeWeight==1){
obj.style.zIndex=5;
obj.strokeWeight=2;
obj.strokeColor="Navy" ;
qID=obj.id;
qName=obj.innerText.replace(/(^/s*)|(/s*$)/g,"");
xx=parseInt(obj.style.left);
yy=parseInt(obj.style.top);
}
//window.event.cancelBubble=true;
// ppp.innerText=xx+":"+yy;
}
function setSel(obj,tempX,tempY){
//如果手中无棋,选中棋子,否则确定目标点
if(qID!="" && qID!=obj.id){
setTarget(tempX,tempY);
}
//selectNull();
if(obj.strokeWeight==1){
obj.style.zIndex=5;
obj.strokeWeight=2;
obj.strokeColor="Navy" ;
qID=obj.id;
qName=obj.innerText.replace(/(^/s*)|(/s*$)/g,"");
xx=parseInt(obj.style.left);
yy=parseInt(obj.style.top);
}
// ppp.innerText=xx+":"+yy;
}
function target(){
//选中目标
if(whosTurn !="w" ){return;}
if(qID=="" ){return;}
if(!rule(qName,xx,yy,tempX,tempY)){return;}
if( tempX<-20 ||tempX > 380){return;}
if(tempY<-20||tempY>430){return;}
if(objId==qID){return;}
if(tempX==xx && tempY==yy){return;}
var tempX=(parseInt(event.clientX) - 62) / 50;
var tempY=(parseInt(event.clientY) - 62) / 50;
tempX=(50 * Math.round(tempX)) -20;
tempY=(50 * Math.round(tempY)) -20;
var objId=getQ_xy(tempX,tempY);
// ppp.innerText= tempX.toString() + ":" + tempY.toString();
xxx=tempX;
yyy=tempY;
if (objId ==""){
//alert(1);
getMove(document.getElementById(qID),xx,yy,xxx,yyy);
gogo(xxx,yyy);//走过去
selectNull();
think();
}
else{
if(document.getElementById(getQ_xy(xxx,yyy)).fillColor != myColor){
getMove(document.getElementById(qID),xx,yy,xxx,yyy);
eat(getQ_xy(xxx,yyy),xxx,yyy);
selectNull();
think();
}
}
}
function setTarget(tempX,tempY){
//选中目标
//ppp.innerText= tempX.toString() + ":" + tempY.toString();
if(qID=="" || rule(qName,xx,yy,tempX,tempY)==false || (tempX<-20 ||tempX > 380||tempY<-20||tempY>430) ){
return;
}
xxx=tempX;
yyy=tempY;
if (getQ_xy(xxx,yyy) ==""){
gogo(xxx,yyy);//走过去
}
else{
if(document.getElementById(getQ_xy(xxx,yyy)).fillColor != myColor){
eat(getQ_xy(xxx,yyy),xxx,yyy);
}
}
}
function selectNull(){
for(i=1 ;i<=qiNum;i++){
document.getElementById("q" + i).strokeWeight=1;
document.getElementById("q" + i).style.zIndex=3;
document.getElementById("q" + i).strokeColor="black" ;
}
qID="";
qName="";
xx=0;
yy=0;
xxx=0;
yyy=0;
}
//********以下是走棋和杀棋部分********
function gogo(x,y){
if (qID !=""){
var obj=document.getElementById(qID);
obj.style.left=x;
obj.style.top=y;
obj.style.zIndex=3;
//selectNull();
}
}
function eat(deadID,x,y){
//吃掉对方棋子
eatNum+=1;
var obj=document.getElementById(deadID);
obj.style.top=(eatNum-1) * 50;
obj.style.left=500;
//document.getElementById(deadID).style.display="none";
gogo(x,y);//走过去
if(isKing(deadID)){
if(window.confirm("你取得了胜利!重来吗?"))
{
window.location.reload();
}
}
}
//*********以下是行棋规则部分*************
//走棋规则
function rule(chessName,x1,y1,x2,y2){
var targetChessId=getQ_xy(x2,y2);
if(targetChessId!="")
{
var targetChess =document.getElementById(targetChessId);
if(targetChess.fillColor==myColor)
{
gogo(x1,y1);
return(false);
}
}
var rtn=false;
chessName=chessName.replace(/ /ig,"");
switch (chessName){
case "车":
rtn=ruleChe(x1,y1,x2,y2);
break;
case "马":
rtn=ruleMa(x1,y1,x2,y2);
break;
case "象":
rtn=ruleXiang(x1,y1,x2,y2);
break;
case "相":
rtn=ruleXiang(x1,y1,x2,y2);
break;
case "士":
rtn=ruleShi(x1,y1,x2,y2);
break;
case "仕":
rtn=ruleShi(x1,y1,x2,y2);
break;
case "将":
rtn=ruleJiang(x1,y1,x2,y2);
break;
case "帅":
rtn=ruleJiang(x1,y1,x2,y2);
break;
case "炮":
rtn=rulePao(x1,y1,x2,y2);
break;
case "兵":
rtn=ruleBing(x1,y1,x2,y2);
break;
case "卒":
rtn=ruleBing(x1,y1,x2,y2);
break;
default:
rtn=false;
break;
}
return(rtn);
}
//车的走法
function ruleChe(x1,y1,x2,y2){
var rtn=false;
//1,面积是0
var area=getArea(x1,y1,x2,y2);
if(area==0){
//2,前进路上无其他子
if((( isX(x1,y1,x2,y2) ) && (getQ_x(x1,x2,y1) =="") )||(( !isX(x1,y1,x2,y2) ) && (getQ_y(y1,y2,x1) =="") ) ){
rtn=true;
}
}
return(rtn);
}
//马的走法
function ruleMa(x1,y1,x2,y2){
var rtn=false;
//1,面积是50 * 100
var area=getArea(x1,y1,x2,y2);
if(area==5000 ){
//2,长轴上无子
if ( ( (isX(x1,y1,x2,y2)==true) && (getQ_xy((x1+x2)/2,y1)=="") ) || ( (isX(x1,y1,x2,y2)==false) && ( getQ_xy(x1,(y2+y1)/2)=="") )){
rtn=true;
}
}
return(rtn);
}
//象的走法
function ruleXiang(x1,y1,x2,y2){
var rtn=false;
//1,面积是100 * 100 而且不是大飞
var area=getArea(x1,y1,x2,y2);
if(area==10000 && (Math.abs((y1-y2))==Math.abs((x1-x2)))){
//2,不过河y2>=230
if(y2>=230){
//3,无象眼(x2+x1)/2,(y2+y1)/2位置无棋子
if(getQ_xy((x2+x1)/2,(y2+y1)/2)==""){
rtn=true;
}
}
}
return(rtn);
}
//士的走法
function ruleShi(x1,y1,x2,y2){
var rtn=false;
//1,面积是50*50
var area=getArea(x1,y1,x2,y2);
if(area==2500 ){
//2,不出9宫x2(130-230)y2(330-430)
if(x2>=130 && x2<=230 && y2>=330 && y2<=430){
rtn=true;
}
}
return(rtn);
}
//将的走法
function ruleJiang(x1,y1,x2,y2){
var rtn=false;
//1,某方向只走一格
if(isSingle(x1,y1,x2,y2)){
//2,不出9宫x2(130-230)y2(330-430)
if(x2>=130 && x2<=230 && y2>=330 && y2<=430){
rtn=true;
}
}
//3,照面可以笑杀:在y轴和对方老将中间无棋
//如果是老将,并且满足车的走法
var tempID=getQ_xy(x2,y2);
if(isKing(tempID) && ruleChe(x1,y1,x2,y2)){
rtn=true;
}
return(rtn);
}
//炮的走法
function rulePao(x1,y1,x2,y2){
var rtn=false;
//0,满足车的走法,并且目标点没有棋子
if(ruleChe(x1,y1,x2,y2)==true && getQ_xy(x2,y2)==""){
rtn=true;
}
else{
//或者满足下面走法:
//1,面积是0
var area=getArea(x1,y1,x2,y2);
if(area==0 ){
//2,目标位置是敌人
var tempID=getQ_xy(x2,y2);
if(isEnemy(tempID)){
//2,中间有且只有一个棋子
if( ( (isX(x1,y1,x2,y2) ==false) && ( getQ_y(y1,y2,x1).length==2 || getQ_y(y1,y2,x1).length==3) )||( (isX(x1,y1,x2,y2) == true) && ( getQ_x(x1,x2,y1).length==2 || getQ_x(x1,x2,y1).length==3 ) ) ){
rtn=true;
}
}
}
}
return(rtn);
}
//兵的走法
function ruleBing(x1,y1,x2,y2){
var rtn=false;
//1,不能后退
if(y2-y1<=0){
//2,只走一格
if(isSingle(x1,y1,x2,y2)){
//3,过河前竖走
if(y1>=230 && (!isX(x1,y1,x2,y2))){
rtn=true;
}
//4,过河后随便
if(y1<230){
rtn=true;
}
}
}
return(rtn);
}
//*********以下是行棋规则辅助函数部分***********
function getArea(x1,y1,x2,y2){
//得到面积
var rtn=0;
rtn=Math.abs((x1-x2)*(y1-y2));
return(rtn);
}
function isX(x1,y1,x2,y2){
//判断是否x方向比y方向长
var rtn=false;
if (Math.abs(y1-y2)<Math.abs(x1-x2)){
rtn=true;
}
return(rtn);
}
function isSingle(x1,y1,x2,y2){
//是否某方向只动了一格
var rtn=false;
//1,面积是0
var area=getArea(x1,y1,x2,y2);
if(area==0 ){
//两面只能一格
if ( ( (!isX(x1,y1,x2,y2)) && Math.abs(y1-y2)==50 ) || ( isX(x1,y1,x2,y2) && Math.abs(x1-x2)==50 )){
rtn=true;
}
}
return(rtn);
}
//*********以下是得到棋盘某点线状态部分************
function getQ_xy(x,y){
//得到某点棋子id
var rtn="";
for(j=1;j <= 32;j++){
if (parseInt(document.getElementById("q" +j ).style.left)==x && parseInt(document.getElementById("q" +j ).style.top)==y){
rtn="q" + j;
}
}
//qqq.innerText=rtn ;
return(rtn.replace(/(^/s*)|(/s*$)/g,""));
}
function getQ_x(x1,x2,y){
//得到x轴向两点的棋子id连接的字串
var rtn="";
for(i=Math.min(x1,x2)+50;i<Math.max(x1,x2);i+=50){
rtn+=getQ_xy(i,y);
}
return(rtn.replace(/(^/s*)|(/s*$)/g,""));
}
function getQ_y(y1,y2,x){
//得到y轴向两点的棋子id连接的字串
var rtn="";
for(i=Math.min(y1,y2)+50;i<Math.max(y1,y2);i+=50){
rtn+=getQ_xy(x,i);
}
//qqq.innerText=rtn ;
return(rtn.replace(/(^/s*)|(/s*$)/g,""));
}
//判断某点是否是敌人
function isEnemy(tempID){
var rtn=false;
if (tempID!=""){
if(document.getElementById(tempID).fillColor != myColor){
rtn=true;
}
}
return(rtn);
}
//判断某点是否是敌人老将
function isKing(tempID){
var rtn=false;
if (isEnemy(tempID)){
var kingName=document.getElementById(tempID).innerText.replace(/(^/s*)|(/s*$)/g,"");
if( kingName=="将" || kingName=="帅" ){
rtn=true;
}
}
return(rtn);
}
</script>
<title>超级大笨狼象棋</title>
</head>
<body onselectstart="document.selection.clear();" οncοntextmenu="selectNull();return(false);">
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<v:group style="top: 0; left: 0; width: 400px; height: 450px; position: relative;"
coordorig="0,0" coordsize="400,450">
<v:rect id="qiPan" style="position: relative; width: 460; height: 510px; top=-30;
left=-30; z-index: 1;" fillcolor="#f0e68c" strokeweight="2">
<v:textbox inset="80pt,180pt,1pt,1pt" style="z-index: 2; font-size=24; font-weight: bold;
position: relative; letter-spacing: 2em; color='#cc9933'; filter: glow(color=#ffffff,strength=1) alpha(opacity=90);
cursor: default;"> 楚河汉界</v:textbox>
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
</v:rect>
<v:line from="0,0" to="400,0" style="z-index: 3; filter: " strokeweight="1pt">
</v:line>
<v:line from="0,50" to="400,50" style="z-index: 3; filter: " strokeweight="1pt">
</v:line>
<v:line from="0,100" to="400,100" style="z-index: 3; filter: " strokeweight="1pt">
</v:line>
<v:line from="0,150" to="400,150" style="z-index: 3; filter: " strokeweight="1pt">
</v:line>
<v:line from="0,200" to="400,200" style="z-index: 3; filter: " strokeweight="1pt">
</v:line>
<v:line from="0,250" to="400,250" style="z-index: 3; filter: " strokeweight="1pt">
</v:line>
<v:line from="0,300" to="400,300" style="z-index: 3; filter: " strokeweight="1pt">
</v:line>
<v:line from="0,350" to="400,350" style="z-index: 3; filter: " strokeweight="1pt">
</v:line>
<v:line from="0,400" to="400,400" style="z-index: 3; filter: " strokeweight="1pt">
</v:line>
<v:line from="0,450" to="400,450" style="z-index: 3; filter: " strokeweight="1pt">
</v:line>
<v:line from="0,0" to="0,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="400,0" to="400,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="0,0" to="0,200" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="50,0" to="50,200" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="100,0" to="100,200" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="150,0" to="150,200" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="200,0" to="200,200" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="250,0" to="250,200" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="300,0" to="300,200" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="350,0" to="350,200" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="400,0" to="400,200" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="0,250" to="0,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="50,250" to="50,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="100,250" to="100,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="150,250" to="150,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="200,250" to="200,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="250,250" to="250,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="300,250" to="300,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="350,250" to="350,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="400,250" to="400,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="150,0" to="250,100" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="250,0" to="150,100" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="150,350" to="250,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="250,350" to="150,450" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="55,105" to="55,110" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="55,105" to="60,105" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="55,95" to="55,90" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="55,95" to="60,95" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="45,105" to="45,110" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="45,105" to="40,105" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="45,95" to="45,90" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="45,95" to="40,95" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="355,105" to="355,110" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="355,105" to="360,105" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="355,95" to="355,90" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="355,95" to="360,95" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="345,105" to="345,110" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="345,105" to="340,105" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="345,95" to="345,90" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="345,95" to="340,95" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="55,355" to="55,360" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="55,355" to="60,355" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="55,345" to="55,340" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="55,345" to="60,345" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="45,355" to="45,360" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="45,355" to="40,355" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="45,345" to="45,340" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="45,345" to="40,345" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="355,355" to="355,360" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="355,355" to="360,355" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="355,345" to="355,340" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="355,345" to="360,345" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="345,355" to="345,360" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="345,355" to="340,355" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="345,345" to="345,340" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="345,345" to="340,345" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="105,155" to="105,160" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="105,155" to="110,155" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="105,145" to="105,140" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="105,145" to="110,145" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="95,155" to="95,160" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="95,155" to="90,155" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="95,145" to="95,140" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="95,145" to="90,145" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="205,155" to="205,160" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="205,155" to="210,155" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="205,145" to="205,140" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="205,145" to="210,145" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="195,155" to="195,160" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="195,155" to="190,155" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="195,145" to="195,140" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="195,145" to="190,145" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="305,155" to="305,160" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="305,155" to="310,155" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="305,145" to="305,140" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="305,145" to="310,145" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="295,155" to="295,160" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="295,155" to="290,155" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="295,145" to="295,140" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="295,145" to="290,145" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="105,305" to="105,310" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="105,305" to="110,305" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="105,295" to="105,290" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="105,295" to="110,295" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="95,305" to="95,310" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="95,305" to="90,305" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="95,295" to="95,290" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="95,295" to="90,295" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="205,305" to="205,310" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="205,305" to="210,305" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="205,295" to="205,290" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="205,295" to="210,295" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="195,305" to="195,310" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="195,305" to="190,305" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="195,295" to="195,290" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="195,295" to="190,295" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="305,305" to="305,310" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="305,305" to="310,305" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="305,295" to="305,290" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="305,295" to="310,295" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="295,305" to="295,310" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="295,305" to="290,305" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="295,295" to="295,290" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="295,295" to="290,295" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="395,155" to="395,160" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="395,155" to="390,155" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="395,145" to="395,140" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="395,145" to="390,145" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="395,305" to="395,310" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="395,305" to="390,305" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="395,295" to="395,290" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="395,295" to="390,295" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="5,155" to="5,160" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="5,155" to="10,155" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="5,145" to="5,140" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="5,145" to="10,145" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="5,305" to="5,310" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="5,305" to="10,305" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="5,295" to="5,290" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:line from="5,295" to="10,295" style="z-index: 3;" strokeweight="1pt">
</v:line>
<v:oval id="q1" style="left: -20; top: -20; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q1">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">车</v:textbox>
</v:oval>
<v:oval id="q2" style="left: 30; top: -20; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q2">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">马</v:textbox>
</v:oval>
<v:oval id="q3" style="left: 80; top: -20; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q3">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">象</v:textbox>
</v:oval>
<v:oval id="q4" style="left: 130; top: -20; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q4">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">士</v:textbox>
</v:oval>
<v:oval id="q5" style="left: 180; top: -20; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q5">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">将</v:textbox>
</v:oval>
<v:oval id="q6" style="left: 230; top: -20; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q6">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">士</v:textbox>
</v:oval>
<v:oval id="q7" style="left: 280; top: -20; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q7">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">象</v:textbox>
</v:oval>
<v:oval id="q8" style="left: 330; top: -20; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q8">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">马</v:textbox>
</v:oval>
<v:oval id="q9" style="left: 380; top: -20; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q9">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">车</v:textbox>
</v:oval>
<v:oval id="q10" style="left: 30; top: 80; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q10">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">炮</v:textbox>
</v:oval>
<v:oval id="q11" style="left: 330; top: 80; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q11">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">炮</v:textbox>
</v:oval>
<v:oval id="q12" style="left: -20; top: 130; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q12">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">卒</v:textbox>
</v:oval>
<v:oval id="q13" style="left: 80; top: 130; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q13">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">卒</v:textbox>
</v:oval>
<v:oval id="q14" style="left: 180; top: 130; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q14">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">卒</v:textbox>
</v:oval>
<v:oval id="q15" style="left: 280; top: 130; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q15">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">卒</v:textbox>
</v:oval>
<v:oval id="q16" style="left: 380; top: 130; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="gray" strokeweight="1" οnclick="sel(this);" title="q16">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">卒</v:textbox>
</v:oval>
<v:oval id="q17" style="left: -20; top: 280; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q17">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">兵</v:textbox>
</v:oval>
<v:oval id="q18" style="left: 80; top: 280; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q18">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">兵</v:textbox>
</v:oval>
<v:oval id="q19" style="left: 180; top: 280; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q19">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">兵</v:textbox>
</v:oval>
<v:oval id="q20" style="left: 280; top: 280; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q20">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">兵</v:textbox>
</v:oval>
<v:oval id="q21" style="left: 380; top: 280; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q21">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">兵</v:textbox>
</v:oval>
<v:oval id="q22" style="left: 30; top: 330; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q22">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">炮</v:textbox>
</v:oval>
<v:oval id="q23" style="left: 330; top: 330; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q23">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">炮</v:textbox>
</v:oval>
<v:oval id="q24" style="left: -20; top: 430; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q24">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">车</v:textbox>
</v:oval>
<v:oval id="q25" style="left: 30; top: 430; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q25">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">马</v:textbox>
</v:oval>
<v:oval id="q26" style="left: 80; top: 430; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q26">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">相</v:textbox>
</v:oval>
<v:oval id="q27" style="left: 130; top: 430; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q27">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">仕</v:textbox>
</v:oval>
<v:oval id="q28" style="left: 180; top: 430; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q28">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">帅</v:textbox>
</v:oval>
<v:oval id="q29" style="left: 230; top: 430; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q29">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">仕</v:textbox>
</v:oval>
<v:oval id="q30" style="left: 280; top: 430; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q30">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">相</v:textbox>
</v:oval>
<v:oval id="q31" style="left: 330; top: 430; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q31">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">马</v:textbox>
</v:oval>
<v:oval id="q32" style="left: 380; top: 430; width: 40; height: 40; z-index: 9; cursor: hand;"
fillcolor="red" strokeweight="1" οnclick="sel(this);" title="q32">
<v:shadow on="Ture" type="single" color="#8b4513" offset="3px,3px" />
<v:textbox inset="2pt,2pt,1pt,1pt" style="z-index: 4; font-size=24; font-weight: bold;
filter: glow(color=#ffffff,strength=1);">车</v:textbox>
</v:oval>
</v:group>
<div id="ppp" style="position:absolute;top:50;left:700;font-size:12px;">
现在该你红棋走了,请拖动棋子,本程序只支持IE,如果IE不能正常显示,请设置为信任站点</div>
<div style="position:absolute;top:100;left:700;font-size:12px;">
<button οnclick="Retract();" id="RetractChess">悔棋</button>
<button οnclick="window.location.reload();">重来</button>
<button οnclick="Change();">变着</button>
<button οnclick="bug.click();">报告Bug</button><A id="bug" href="mailto:wolf.pan@kuqu.com?subject=I_find_a_bug!&body=I_find_a_bug:"></A>
</div>
<textarea id="qqq" style="position:absolute;top:150;left:700;font-size:12px;width:200px;height:350px;"></textarea>
<script language="javascript" type="text/javascript">
//p.StandardInput.WriteLine("position fen 4C4/4a4/b2ank2b/9/9/1RNR1crC1/3r1p3/3cKA3/4A4/4n4 w - - 0 1");
//move(30,80,180,80);
function msg(x)
{
//alert(unescape(x));
}
//bestmove d4f4 ponder g4f4
//以下是棋子动画部分
function bestmove(str)
{
window.status=unescape( str);
if(str.length==4)
{
window.clearTimeout(timeOut);
str=str.toLowerCase();
var x1=(str.charCodeAt(0)-97)*50-20;
var y1=430-parseInt(str.substr(1,1)) * 50;
var x2=(str.charCodeAt(2)-97)*50-20;
var y2=430-parseInt(str.substr(3,1))* 50;
//alert(" " + x1 + "," +y1 + "," + x2 + "," +y2 +" " );
move(x1,y1,x2,y2)
}
else
{
Timming();
// ppp.innerHTML=(unescape( str).replace(//n/ig,"<br/>"));
}
RetractChess.disabled=false;
}
var timeOut=0;
function move(x1,y1,x2,y2)
{
var moveChess=document.getElementById( getQ_xy(x1,y1) );
myColor= "gray" ;
enemyColor="red";
//setSel(moveChess,x1,y1);
//setTarget(x2,y2);//走过去
var deadId=getQ_xy(x2,y2);
//纪录棋谱;
getMove(moveChess,x1,y1,x2,y2);
if( deadId !=""){
eatNumRed+=1;
var deadChess=document.getElementById(deadId);
deadChess.style.top=(eatNumRed -1)* 50;
deadChess.style.left=550;
if(isKing(deadId)){
if(window.confirm("你输了!重来吗?"))
{
window.location.reload();
}
}
}
//document.getElementById(deadID).style.display="none";
moveChess.style.top=y2;
moveChess.style.left=x2;
if(moveChess.strokeWeight==1){
moveChess.style.zIndex=5;
moveChess.strokeWeight=2;
moveChess.strokeColor="Navy" ;
}
myColor= "red" ;
enemyColor="gray";
whosTurn="w";
selectNull();
ppp.innerHTML="现在该你红棋走了,请拖动棋子";
}
//以下是拖动棋子部分
var isDrag=false;
var allChess=document.getElementsByTagName("OVAL");
for(i=0;i<allChess.length;i++)
{
//点下
if(allChess[i].fillColor == myColor ) {
allChess[i].οnmοusedοwn=function MouseDown(){
if(event.button==2){return false ;}
if(whosTurn!="w"){return false;}
chessObj=this;
sel(this ) ;
chessObj.setCapture();
chessObj.l=event.x-chessObj.style.pixelLeft;
chessObj.t=event.y-chessObj.style.pixelTop;
}
//移动
allChess[i].οnmοusemοve=function MouseMove(){
if(whosTurn!="w"){return false;}
if(chessObj!=null){
chessObj.style.left = event.x-chessObj.l;
chessObj.style.top = event.y-chessObj.t;
//isDrag
// if(Math.abs( event.y-yy) >=50 || Math.abs(event.x-xx) >=50){isDrag=true;}else{isDrag=false;}
//window.status=isDrag;
}
}
//抬起
allChess[i].οnmοuseup=function MouseUp(){
if(whosTurn!="w"){return false;}
//if(!isDrag){gogo(xx,yy);chessObj=null;return false;}
if(chessObj!=null){
yyy= 50* Math.round(parseInt(chessObj.style.top)/50 )-20;
xxx= 50* Math.round(parseInt(chessObj.style.left)/50 )-20;
//window.status=" " + xxx +" "+ yyy;
chessObj.releaseCapture();
//chessObj.style.top =yyy;
//chessObj.style.left =xxx;
var ok=false;
if(((xxx-xx)!=0 || (yyy-yy)!=0) && xxx<=380 && yyy<=430 && xxx>=-20 && yyy>=-20)
{
if(rule(chessObj.innerText,xx,yy,xxx,yyy) )
{
ok=true;
var XXX=xxx;
var YYY=yyy;
var XX=xx;
var YY=yy;
// gogo(xxx,yyy);//走过去
if (getQ_xy(xxx,yyy) ==""){
getMove(chessObj,XX,YY,XXX,YYY);
gogo(xxx,yyy);//走过去
}
else{
var deadChessId=getQ_xy(XXX,YYY);
var deadChess=document.getElementById(deadChessId);
getMove(chessObj,XX,YY,XXX,YYY);
eat(deadChessId,XXX,YYY);
}
think();
}
}
if(!ok){gogo(xx,yy);}
chessObj=null;
}
//selectNull();
}
}
}
function think()
{
whosTurn="b";
selectNull();
var fen=getPosition();
var cmd="position fen " + fen + " b - - 0 2"+ "/n";
// 判断长捉长将,三步必须变着;
//alert(moveArray + ":"+moveArray.length);
var Len=moveArray.length;
if( moveArray.length>6 && (Len % 2 ==0) )
{
if((moveArray[Len-1] + moveArray[Len-2])== (moveArray[Len-3] + moveArray[Len-4]) )
{
if((moveArray[Len-3] + moveArray[Len-4])== (moveArray[Len-5] + moveArray[Len-6]) )
{
Timming();
cmd+="banmoves " + moveArray[Len-1] + "/n";
}
}
//if(moveArray)
}
//延迟30秒后如果没应着就算你赢了。
//在黑方走棋的时候不允许点悔棋按钮。
RetractChess.disabled=true;
timeOut =window.setTimeout("Timming()",1000 * 30);
PageMethods("blackMove","","bestmove", cmd,1000);
ppp.innerHTML="这步棋走的好!笨狼正在思考,请稍候!~~";
}
function Timming()
{
//增加难度;
PageMethods("addTime","","",1000);
//如果服务器半分钟没做出反映自动判负。
if(window.confirm("笨狼想不出对策,算你赢了!重来吗?"))
{
window.location.reload();
}
}
function isChessRed(chessObj)
{
return (chessObj.fillColor=="red");
}
function autoMove(objId,x2,y2)
{
var moveChess=document.getElementById(objId );
moveChess.style.top=y2;
moveChess.style.left=x2;
myColor= "red" ;
enemyColor="gray";
whosTurn="w";
ppp.innerHTML="后悔了吧?现在该你红棋走了,请拖动棋子";
}
function displayChineseMoves()
{
qqq.value="";
for(i=0;i<moveChineseArray.length;i++)
{
if(i % 2 ==0){qqq.value +="第"+ parseInt (i/2 + 1)+ "步:" + moveChineseArray[i]+ " ";}else{qqq.value +=moveChineseArray[i]+ "/n";}
}
}
function Retract()
{
if(RetractArray.length>0)
{
RetractOne();
RetractOne();
displayChineseMoves();
}
else
{
alert("目前回到最原始状态了,没棋可悔了!~~");
}
}
function Change()
{
var Len=moveArray.length;
if(Len>=2 && (Len % 2==0))
{
var lastMove=moveArray[Len-1];
RetractOne();
displayChineseMoves();
whosTurn="b";
selectNull();
var fen=getPosition();
var cmd="position fen " + fen + " b - - 0 2"+ "/n";
cmd+="banmoves " + lastMove+ "/n";
//alert(cmd);
timeOut =window.setTimeout("Timming()",1000 * 30);
RetractChess.disabled=true;
PageMethods("blackMove","","bestmove", cmd,3000);
ppp.innerHTML="要变着,笨狼需要多思考,可能找不到变着,请稍候!~~";
}
else
{
alert("无着可变!~~");
}
}
function RetractOne()
{
var str=RetractArray[RetractArray.length-1];
var arr=str.split(" ");
if(arr.length==6)
{
autoMove(arr[0],arr[1],arr[2]);
autoMove(arr[3],arr[4],arr[5]);
}
if(arr.length==3)
{
autoMove(arr[0],arr[1],arr[2]);
}
RetractArray.pop();
moveChineseArray.pop();
moveArray.pop();
}
//以下是得到棋谱部分
function getMove(chessObj,x1,y1,x2,y2)
{
var deadId=getQ_xy(x2,y2);
if(deadId=="")
{
RetractArray.push( chessObj.id + " " + x1 + " " + y1 ) ;
}
else
{
RetractArray.push( chessObj.id + " " + x1 + " " + y1 + " " + deadId + " " + x2 + " " + y2) ;
}
var chessName= chessObj.innerText.replace(/ /ig,"");
var re=chessName ;
var isRed=isChessRed(chessObj );
var moveCode="";
if(isRed){
moveCode=String.fromCharCode(65+(x1+20)/50) + ((y1+20)/50) + String.fromCharCode(65+(x2+20)/50) + ((y2+20)/50);
}
else{
moveCode=String.fromCharCode(97+(x1+20)/50) + ((y1+20)/50) + String.fromCharCode(97+(x2+20)/50) + ((y2+20)/50);
}
moveArray.push(moveCode);
var arr=new Array("一","二","三","四","五","六","七","八","九");
if(y1==y2) {
if(isRed) { re+= arr[8-(x1+20)/50];}else{re+=1+(x1+20)/50;}
}
if(y1>y2 ) {
if(isRed){ re+=arr[8-(x1+20)/50] ;}else{re+=1+(x1+20)/50;}
}
if(y1<y2) {
if(isRed) { re+=arr[8-(x1+20)/50] ;}else{ re+=1+(x1+20)/50 ;}
}
for(i=-20;i<=480;i+=50)
{
var tempObjId=getQ_xy(x1,i);
if(tempObjId!="")
{
var tempObj=document.getElementById(getQ_xy(x1,i));
if((tempObj.id!=chessObj.id) && (tempObj.fillColor==chessObj.fillColor) && (tempObj.innerText==chessObj.innerText))
{
if( isRed && i<y1 || (!isRed && i>y1) ) {re="前" + chessName;}else { re="后" + chessName;}
break;
}
}
}
//下边是后续部分
if(y1==y2) {
if(isRed){re+= "平" + arr[8-(x2+20)/50];} else{re+= "平" + (1+(x2+20)/50);}
}
if(y1>y2 ) {
if(isRed)
{
if(x1==x2){ re+= "进" + arr[Math.abs(y2-y1)/50-1];}else{re+= "进" + arr[ 8-(x2+20)/50];}
}
else
{
if(x1==x2){ re+= "退" + Math.abs(y2-y1)/50;}else{re+= "退" + (1+(x2+20)/50);}
}
}
if(y1<y2) {
if(isRed)
{
if(x1==x2){ re+= "退" + arr[Math.abs(y2-y1)/50-1];}else{re+= "退" + arr[ 8-(x2+20)/50];}
}
else
{
if(x1==x2){re+= "进" + Math.abs(y2-y1)/50;}else{re+= "进" + ( 1+(x2+20)/50 );}
}
}
moveChineseArray.push(re);
displayChineseMoves();
//if(!isRed){ re+= "<br/>"}else{ re+= " "}
}
//以下是得到棋盘状态部分
function getPosition()
{
var re="";
var last=0;
for(y=-20 ;y<=430;y+=50)
{
for(x=-20 ;x<=380;x+=50)
{
if(getQ_xy(x,y)!="")
{
var obj=document.getElementById(getQ_xy(x,y));
var chessName=obj.innerText.replace(/ /ig,'');
//rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR
switch (chessName){
case "车":
chessName="r";
break;
case "马":
chessName="n";
break;
case "象":
chessName="b";
break;
case "相":
chessName="b";
break;
case "士":
chessName="a";
break;
case "仕":
chessName="a";
break;
case "将":
chessName="k";
break;
case "帅":
chessName="k";
break;
case "炮":
chessName="c";
break;
case "兵":
chessName="p";
break;
case "卒":
chessName="p";
break;
}
if(obj.fillColor=="red")
{
chessName=chessName.toUpperCase();
}
if(last>0)
{
re+=last;
last=0;
}
re+=chessName;
obj.innerText.replace(/ /ig,'');
last=0;
}
else
{
last++;
}
}
if(last>0)
{
re+=last;
last=0;
}
re+="/";
}
re = re.substring(0,re.length-1) ;
return re;
}
</script>
</body>
</html>
using System;
using System.Data;
using System.IO;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Collections.Generic;
namespace SuperDullWolfChess
{
public class BasePage : System.Web.UI.Page
{
public BasePage()
{
}
protected override void OnPreInit(EventArgs e)
{
if (Convert.ToInt32(HttpContext.Current.Request["ISAJAXREQUEST"]) == 1)
{
ExecuteAjaxRequest(HttpContext.Current.Request["AJAXREQUESTFUNNAME"], HttpContext.Current);
}
base.OnPreInit(e);
}
public void ExecuteAjaxRequest(string function, HttpContext context)
{
Response.Clear();
int formFieldCount = context.Request.Form.Count;
object[] arguments;
if (formFieldCount > 0)
arguments = new object[formFieldCount];
else
arguments = null;
Type cls = this.GetType().BaseType;
MethodInfo methodInfo = cls.GetMethod(function, BindingFlags.Public | BindingFlags.Static);
if (methodInfo == null)
{
cls = this.GetType().BaseType.BaseType;
methodInfo = cls.GetMethod(function, BindingFlags.Public | BindingFlags.Static);
}
ParameterInfo[] pars = methodInfo.GetParameters();
for (int i = 0; i < formFieldCount; i++)
{
switch (pars[i].ParameterType.FullName)
{
case "System.Int32":
arguments[i] = Convert.ToInt32(context.Request.Form[i]);
break;
case "System.Decimal":
arguments[i] = Convert.ToDecimal(context.Request.Form[i]);
break;
case "System.String":
arguments[i] = context.Request.Form[i].ToString();
break;
default:
arguments[i] = context.Request.Form[i].ToString();
break;
}
}
//禁止使用.ToString()进行转换
string response = (string)cls.InvokeMember(function,
BindingFlags.Default | BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public,
null, null, arguments);
Response.Write(response);
Response.End();
}
/// <summary>
/// 读取根目录路径
/// </summary>
public string ApplicationRoot
{
get
{
return HttpContext.Current.Request.ApplicationPath;
}
}
protected string description = string.Empty;
protected string keywords = string.Empty;
}
}
using System;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.Diagnostics;
namespace SuperDullWolfChess
{
public class Chess
{
public Chess(string name)
{ }
public string Name;
public int X;
public int Y;
}
public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
public static string isDead(string fen)
{
//判断是否可以将死对方,车马炮兵将5种可能,因为将同车,故4种可能。
//rnbak1bnr/4a4/4c4/p1p3p1C/4c4/9/P1P3P1P/7C1/9/RNBAKABNR
//rnbak1bnr/4a4/4c4/p1p3p1C/4c4/9/P1P3P1P/7C1/9/RNBAKABNR
string[] Arr1 = fen.Split(@"/".ToCharArray());
string[] Arr2 = new string[Arr1.Length];
for (int y = 0; y < Arr1.Length; y++)
{
string tempStr = "";
for (int x = 0; x < Arr1[y].Length; x++)
{
char currentChar = Arr1[y].ToCharArray()[x];
int ascii = (int)(currentChar);
if (ascii < 58 && ascii > 48)
{
//1-9的数字
tempStr += makeString(Convert.ToInt32(currentChar.ToString()));
}
else
{
tempStr += currentChar;
}
}
Arr2[y] = tempStr;
}
//车马炮兵4种可能
List<Chess> Listr = new List<Chess>();
List<Chess> Listn = new List<Chess>();
List<Chess> Listc = new List<Chess>();
List<Chess> Listp = new List<Chess>();
Chess cheesK = new Chess("K");
string[,] Board = new string[9, 10];
for (int y = 0; y < Arr2.Length; y++)
{
for (int x = 0; x < Arr2[y].Length; x++)
{
string currentStr = Arr2[y].Substring(x, 1);
Board[x, 9 - y] = currentStr;
if (currentStr != "0")
{
Chess C = new Chess(currentStr);
C.X = x + 1;
C.Y = 9 - y;
switch (currentStr)
{
case "r": Listr.Add(C);
break;
case "k": Listr.Add(C);
break;
case "n": Listn.Add(C);
break;
case "c": Listc.Add(C);
break;
case "p": Listp.Add(C);
break;
case "K":
cheesK = C;
break;
}
}
else
{
Board[x, 9 - y] = "";
}
}
}
Chess currentChess;
string bestMove = "";
//自此得到了棋盘和棋子状态
//检查车和笑面杀
for (int i = 0; i < Listr.Count; i++)
{
//面积为0
currentChess = Listr[i];
int x1 = currentChess.X;
int y1 = currentChess.Y;
int x2 = cheesK.X;
int y2 = cheesK.Y;
if (ruleChe(x1, y1, x2, y2, Board))
{
bestMove = getBestmove(currentChess, cheesK);
return bestMove;
}
}
//检查马
for (int i = 0; i < Listn.Count; i++)
{
currentChess = Listn[i];
int x1 = currentChess.X;
int y1 = currentChess.Y;
int x2 = cheesK.X;
int y2 = cheesK.Y;
//面积为2
if (ruleMa(x1, y1, x2, y2, Board))
{
// rtn=true;
bestMove = getBestmove(currentChess, cheesK);
return bestMove;
}
}
//检查炮
for (int i = 0; i < Listc.Count; i++)
{
currentChess = Listc[i];
int x1 = currentChess.X;
int y1 = currentChess.Y;
int x2 = cheesK.X;
int y2 = cheesK.Y;
//面积为2
if (rulePao(x1, y1, x2, y2, Board))
{
// rtn=true;
bestMove = getBestmove(currentChess, cheesK);
return bestMove;
}
}
//检查兵
for (int i = 0; i < Listc.Count; i++)
{
currentChess = Listc[i];
int x1 = currentChess.X;
int y1 = currentChess.Y;
int x2 = cheesK.X;
int y2 = cheesK.Y;
//面积为2
if (ruleBing(x1, y1, x2, y2))
{
// rtn=true;
bestMove = getBestmove(currentChess, cheesK);
return bestMove;
}
}
return "0000";
}
//兵的走法
public static bool ruleBing(int x1, int y1, int x2, int y2)
{
bool rtn = false;
//1,不能后退
if (y1 <= y2)
{
//2,只走一格
if (isSingle(x1, y1, x2, y2))
{
//3,过河前竖走
if (y1 <= 5 && (!isX(x1, y1, x2, y2)))
{
rtn = true;
}
//4,过河后随便
if (y1 > 5)
{
rtn = true;
}
}
}
return (rtn);
}
public static bool isSingle(int x1, int y1, int x2, int y2)
{
//是否某方向只动了一格
bool rtn = false;
//1,面积是0
int area = getArea(x1, y1, x2, y2);
if (area == 0)
{
//两面只能一格
if (((!isX(x1, y1, x2, y2)) && Math.Abs(y1 - y2) == 1) || (isX(x1, y1, x2, y2) && Math.Abs(x1 - x2) == 1))
{
rtn = true;
}
}
return (rtn);
}
public static int getArea(int x1, int y1, int x2, int y2)
{
int rtn = 0;
rtn = Math.Abs((x1 - x2) * (y1 - y2));
return (rtn);
}
public static bool ruleMa(int x1, int y1, int x2, int y2, string[,] Board)
{
bool rtn = false;
//1,面积是2
var area = getArea(x1, y1, x2, y2);
if (area == 2)
{
//2,长轴上无子getQ_xy(int x, int y, string[,] Board)
if (((isX(x1, y1, x2, y2) == true) && (getQ_xy(Convert.ToInt32((x1 + x2) / 2), y1, Board).Length == 0)) || ((isX(x1, y1, x2, y2) == false) && (getQ_xy(x1, Convert.ToInt32((y1 + y2) / 2), Board).Length == 0)))
{
rtn = true;
}
}
return (rtn);
}
public static bool rulePao(int x1, int y1, int x2, int y2, string[,] Board)
{
bool rtn = false;
//0,满足车的走法,并且目标点没有棋子
//或者满足下面走法:
//1,面积是0
int area = getArea(x1, y1, x2, y2);
if (area == 0)
{
//2,中间有且只有一个棋子
bool case1 = !isX(x1, y1, x2, y2);
case1 = case1 && (getQ_y(y1, y2, x1, Board).Length == 2);
bool case2 = isX(x1, y1, x2, y2);
case2 = case2 && (getQ_x(x1, x2, y1, Board).Length == 2);
if (case1 || case2)
{
rtn = true;
}
}
return (rtn);
}
public static string getQ_xy(int x, int y, string[,] Board)
{
//得到某点棋子id
return (Board[x - 1, y]);
}
public static string getQ_x(int x1, int x2, int y, string[,] Board)
{
//得到x轴向两点的棋子id连接的字串
string rtn = "";
for (int i = Math.Min(x1, x2); i < Math.Max(x1, x2); i++)
{
rtn += getQ_xy(i, y, Board);
}
return (rtn);
}
public static bool ruleChe(int x1, int y1, int x2, int y2, string[,] Board)
{
bool rtn = false;
//1,面积是0
int area = getArea(x1, y1, x2, y2);
if (area == 0)
{
//2,前进路上无其他子
if (((isX(x1, y1, x2, y2)) && (getQ_x(x1, x2, y1, Board).Length == 1)) || ((!isX(x1, y1, x2, y2)) && (getQ_y(y1, y2, x1, Board).Length == 1)))
{
rtn = true;
}
}
return (rtn);
}
public static string getQ_y(int y1, int y2, int x, string[,] Board)
{
//得到y轴向两点的棋子id连接的字串
string rtn = "";
for (int i = Math.Min(y1, y2); i < Math.Max(y1, y2); i++)
{
rtn += getQ_xy(x, i, Board);
}
return (rtn);
}
public static bool isX(int x1, int y1, int x2, int y2)
{
//判断是否x方向比y方向长
bool rtn = false;
if (Math.Abs(y1 - y2) < Math.Abs(x1 - x2))
{
rtn = true;
}
return (rtn);
}
public static string getBestmove(Chess A, Chess B)
{
string bestMove = "";
bestMove += (char)(A.X + 96);
bestMove += A.Y;
bestMove += (char)(B.X + 96);
bestMove += B.Y;
return bestMove;
}
public static bool hasChessX(Chess A, Chess B, string[,] Board)
{
bool re = true;
int min = A.X;
int max = B.X;
if (A.X > B.X)
{
min = B.X;
max = A.X;
}
for (int i = min; i <= max; i++)
{
if (Board[i - 1, A.X] != "0")
{
re = false;
break;
}
}
return re;
}
public static bool hasChessY(Chess A, Chess B, string[,] Board)
{
bool re = true;
int min = A.Y;
int max = B.Y;
if (A.Y > B.Y)
{
min = B.Y;
max = A.Y;
}
for (int i = min; i <= max; i++)
{
if (Board[i - 1, A.X] != "0")
{
re = false;
break;
}
}
return re;
}
public static string makeString(int x)
{
string re = "";
for (int i = 0; i < x; i++)
{
re += "0";
}
return re;
}
public static void addTime(int time)
{
//如果人赢了电脑,那么思考时间增加1秒。
if (HttpContext.Current.Session["addTime"] != null)
{
HttpContext.Current.Session["addTime"] = Convert.ToInt32(HttpContext.Current.Session["addTime"]) + time;
}
}
public static string blackMove(string cmd,int time)
{
System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"position fen [^ ]* ");
string fen = reg1.Match(cmd).Value.Replace("position fen ","").Trim();
string bestMove = isDead(fen);
if (bestMove == "0000")
{
string strExePath = HttpContext.Current.Server.MapPath(@"bin/ELEEYE.EXE");
Process p = new Process();
p.StartInfo.FileName = strExePath;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine("ucci");
p.StandardInput.WriteLine("setoption batch on");
//p.StandardInput.WriteLine("position fen 4C4/4a4/b2ank2b/9/9/1RNR1crC1/3r1p3/3cKA3/4A4/4n4 w - - 0 1");
//p.StandardInput.WriteLine("position fen " + fen + " b - - 0 0");
string[] arr = cmd.Split("/n".ToCharArray());
for (int i = 0; i < arr.Length; i++)
{
p.StandardInput.WriteLine(arr[i]);
}
if (HttpContext.Current.Session["addTime"] != null)
{
//如果人赢了电脑,那么难度增加。
time += Convert.ToInt32(HttpContext.Current.Session["addTime"]);
}
else
{
HttpContext.Current.Session["addTime"] = 0;
}
p.StandardInput.WriteLine("go time " + time);
p.StandardInput.WriteLine("quit");
string re = p.StandardOutput.ReadToEnd();
p.Close();
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"bestmove[^/n]*/n");
re = reg.Match(re).Value;
if (re.Length > 7)
{
re = re.Substring(8, 5).Trim();
}
else
{
//认输了。
re = "nobestmove";
}
return re;
}
else
{
return bestMove;
}
}
}
}