(声明:本故事纯属脑洞,如有雷同,估计不会吧233;ps:为方便记述可能会对程序代码进行“艺术加工”,非程序员请不要在Java上运行233;本文章仅供娱乐(禁止用作商业用途,emmm,嘛,虽然可能不会有多少人注意吧233),转载请注明出处,欢迎二次创作;)
/**Tuesday 罗伯特型机器人*/
class Player{
//Abstract Function
// Robot_Player会记住: String name,typeOfgame;//所负责的玩家名,记忆中的游戏类型
// char id;//自己的颜色
// Piece[] pieces;//规定棋手的棋子权限
// Action acts;//执行行动的权力(与棋盘“沟通”的能力)
//Representation Invariant
// Robot_Player的记忆可以有部分重复。
// Robot_Player记忆的typeOfgame、id等由Gamer保证匹配。
// Robot_Player具有必备的常识,可保证pieces和acts的权限。
//Safety From Exposure
// 0.Robot_Player的所有记忆是私有且不可继承的。
// 1.Robot_Player不得恶意调用acts权限。
// 2.Robot_Player应遵守真实玩家的命令,除非这违反上一行规定。
// 3.Robot_Player可在必要时对除Gamer外的任何class保持沉默。
private final String name;//所负责的玩家名,记忆中的游戏类型
private final String typeOfgame;//所负责的玩家名,记忆中的游戏类型
private final char id;//自己的颜色
private final Piece[] pieces;//规定棋手的棋子权限
private final Action acts;//执行行动的权力(与棋盘“沟通”的能力)
/**
* Robot_Player学习规则并获取行动权
* @param name 请记住所负责的玩家姓名
* @param type 请记住该局游戏类型,并根据常识完成参数配置
* @param id 请记住改名玩家的身份——颜色(1 for black ; 0 for white ; )
*/
Player(String name,String type,char id){
//(深层记忆写入...)
//该代码为Robot_Player私有
//该代码被折叠
//(成功。)
if(type.equals("chess")){
//(象棋模块导入...)
//该代码为Robot_Player私有
//该代码被折叠
//(成功。)
}
else{
//(围棋模块导入...)
//该代码为Robot_Player私有
//该代码被折叠
//(成功。)
}
//(棋盘沟通能力赋权...)
//该代码为Robot_Player私有
//该代码被折&……%¥&U……%
this.acts=new Action(this.typeOfgame);//(“唔唔……”)
//(成功。)
}
/**
* 询问玩家的决策,并执行或提示错误
* @return true iff 行动执行成功
*/
boolean actioningame(){
String[] seq;
System.out.println("\nI`m cute \"ChessAndGo\" Robot——"+name+".");
System.out.println("Please tell me your determination: ("+name+" with "+id+")");
System.out.println("A:下棋 S:查询位置情况 C:统计棋子数量 J:跳过");
switch (tempString.toLowerCase().charAt(0)) {
case 'j':
System.out.println("Well,please input an enter.");
//该代码为Robot_Player私有
//该代码被折叠
case 'a':
if(this.typeOfgame.equals("chess")){
System.out.println("And tell me Piece(x y) pos.x pos.y");
}
else System.out.println("And tell me pos.x pos.y");
//该代码为Robot_Player私有
//该代码被折叠
seq=tempString.split(" ");
//Player落子(正确性判定)
//Robot_Player应当拒绝真实玩家的错误请求
//1.如格式错误 (System.out.println("Please pay attention to the format~");)
//2.如参数越界 (System.out.println("Wrong param,please watch carefuly.");)
//3.如运行时异常(System.out.println("emmm,I don`t know what you will do……(ascj~)");)
//该代码为Robot_Player私有
//该代码被折叠
//开始阶段
//该代码为Robot_Player私有
//该代码被折叠
for (……)
if (……) //有权限
if (acts.move(piece.piecetype, id, sx, sy, tx, ty)) {
if(this.typeOfgame.equals("go")) judge(tx,ty);
System.out.println("I do that!Please fresh the board by enter~^_^");
//该代码为Robot_Player私有
//该代码被折叠
}
System.out.println("I think that you can`t move this piece.");
return false;
case 's':
//该代码为Robot_Player私有
//该处代码被折叠
acts.seek(x,y);
//该代码为Robot_Player私有
//该代码被折叠
case 'c':
board.caculate(id);
//该代码为Robot_Player私有
//该代码被折叠
default:
System.out.println("emmm,I don`t know what you will do……(ascj~)");
//该代码为Robot_Player私有
//该代码被折叠
}
}
/**
* 判断是否可提子
* @param x target x
* @param y target y
*/
void judge(int x,int y){
//该代码为Robot_Player私有
//该代码被折叠
}
/**
* 显示行动步骤
*/
void review(){
//该代码为Robot_Player私有
//该代码被%……U&¥%……&
System.out.println(acts.seq);
}
}
---------------------
作者:L.L~C
来源:CSDN
原文:https://blog.csdn.net/l1048eif/article/details/89290641
版权声明:本文为博主原创文章,转载请附上博文链接!