package common.utils;
import java.awt.*;
import java.util.*;
import java.util.List;
import static common.constants.Constants.*;
import static common.utils.ChessBoardUtil.*;
public class StrategyUtil {
//几步以下 放置在内圈
static int innerHand = 3;
//往后预判几手
static int deepMind = 1;
public static Point analysis() {
int preHand = 0;
ArrayList<Point> rooms = new ArrayList<>();
//獲取可下的棋盤空間
for (int i = 0; i < CHESSBOARD_SIZE; i++) {
for (int j = 0; j < CHESSBOARD_SIZE; j++) {
if (CHESS_STATUS[i][j] == 0) {
rooms.add(new Point(i, j));
}
}
}
ArrayList<Point> suggest = new ArrayList<>();
suggest.addAll(rooms);
if (HAND < 30) {
//遍历去除外面两圈的点
Iterator<Point> s = suggest.iterator();
while (s.hasNext()) {
Point p = s.next();
//每人的前面两步 建议走内圈
if (HAND < 2*innerHand + 1) {
if (p.getX() < 2 || p.getY() < 2 || p.getX() >= CHESSBOARD_SIZE - 2 || p.getY() >= CHESSBOARD_SIZE - 2) {
s.remove();
}
}
//建议与上次对手下的棋距离4以内
else if (Math.abs(p.getX() - LATEST_PUT.getX()) > 4 || Math.abs(p.getY() - LATEST_PUT.getY()) > 4) {
s.remove();
}
}
}
//每个点位落子后的成绩单。
Map<Point, Integer> report = new HashMap<>();
//挑選的棋子座標
Point pick = null;
Point bestValue = myCalculate(CHESS_STATUS, STATUS, rooms);
for (Point tryChess : suggest) {
if (pick == null) {
pick = tryChess;
}
Point tempValue = tryPut(tryChess, CHESS_STATUS, rooms, STATUS, DAJIE, DAJIE_POINT, LATEST_PUT, preHand);
if (tempValue == null)
continue;
if (bestValue == null) {
bestValue = tempValue;
continue;
}
if ((tempValue.getX() - tempValue.getY()) >= bestValue.getX() - bestValue.getY()) {
bestValue = tempValue;
pick = tryChess;
}
}
return pick;
}
/**
* 递归预演轮流下子
*
* @param put
* @param chessStatus
* @param rooms
* @param currentStat
* @param dajie
* @param dajiePoint
* @param pre_Hand
* @return
*/
static Point tryPut(Point put, int[][] chessStatus, ArrayList<Point> rooms, int currentStat, Boolean dajie, Point dajiePoint, Point latestPut, int pre_Hand) {
int[][] currentBoard = new int[CHESSBOARD_SIZE][CHESSBOARD_SIZE];
for (int i = 0; i < CHESSBOARD_SIZE; i++) {
currentBoard[i] = chessStatus[i].clone();
}
Boolean currentDajie = new Boolean(dajie);
Point currentDajiePoint = new Point(dajiePoint);
Point currentLatestPut = latestPut;
ArrayList<Point> currentRooms = new ArrayList<>();
currentRooms.addAll(rooms);
int currentPreHand = pre_Hand;
int currentHand = HAND + pre_Hand;
List<Point> suggest = new ArrayList<>();
suggest.addAll(rooms);
if (currentHand < 30) {
//遍历去除外面两圈的点
Iterator<Point> s = suggest.iterator();
while (s.hasNext()) {
Point p = s.next();
//每人的开始两步 建议走内圈
if (currentHand < 2*innerHand + 1) {
if (p.getX() < 2 || p.getY() < 2 || p.getX() >= CHESSBOARD_SIZE - 2 || p.getY() >= CHESSBOARD_SIZE - 2) {
s.remove();
}
}
//建议与上次对手下的棋距离四以内
else if (Math.abs(p.getX() - currentLatestPut.getX()) > 4 || Math.abs(p.getY() - currentLatestPut.getY()) > 4) {
s.remove();
}
}
}
//我方成绩单
Map<Point, Integer> myReport = new HashMap<>();
//对方成绩单
Map<Point, Integer> opReport = new HashMap<>();
boolean enableMove = false;
boolean enemyMoveable = false;
int x = (int) put.getX();
int y = (int) put.getY();
Point bestValue = null;
if (putChess(x, y, currentStat, currentBoard, currentDajie, currentDajiePoint)) {
enableMove = true;
//先把各方势力值计算出来,最好成绩缺省值为计算后的成绩
bestValue = myCalculate(currentBoard, currentStat, currentRooms);
//雙方各往下預判几手
if (currentPreHand == deepMind * 2) {
return bestValue;
}
currentPreHand++;
currentRooms.remove(put);
for (Point tryChess : suggest) {
int[][] tempBoard = new int[CHESSBOARD_SIZE][CHESSBOARD_SIZE];
for (int i = 0; i < CHESSBOARD_SIZE; i++) {
tempBoard[i] = currentBoard[i].clone();
}
Boolean tempDajie = new Boolean(currentDajie);
Point tempDajiePoint = new Point(currentDajiePoint);
ArrayList<Point> tempRooms = new ArrayList<>();
tempRooms.addAll(currentRooms);
Point tempValue = tryPut(tryChess, tempBoard, tempRooms, -currentStat, tempDajie, tempDajiePoint, put, currentPreHand);
if (tempValue == null) {
continue;
}
//由于下的是对手棋,X,Y反转
if ((tempValue.getY() - tempValue.getX()) >= bestValue.getY() - bestValue.getX()) {
bestValue = new Point((int)tempValue.getY(),(int)tempValue.getX());
}
}
}
return bestValue;
}
/**
* 落子,并分析该子是否有效
*
* @param x
* @param y
* @param status
* @param currentDajiePoint
* @return
*/
static boolean putChess(int x, int y, int status, int[][] currentBoard, Boolean dajie, Point currentDajiePoint) {
//我方连接体
ArrayList<Point> myLink = new ArrayList<Point>();
//对方连接体
ArrayList<Point> opponentLink = new ArrayList<Point>();
//先判断是否能吃对手
if (opDead(x, y, status, opponentLink, currentBoard)) {
//考虑打劫的情况
if (opponentLink.size() == 1) {
if (dajie && currentDajiePoint.equals(opponentLink.get(0))) {
return false;
} else {
currentDajiePoint = new Point(x, y);
dajie = true;
}
} else {
dajie = false;
}
//腾出棋盘空间
for (Point death : opponentLink) {
currentBoard[(int) death.getX()][(int) death.getY()] = 0;
}
currentBoard[x][y] = status;
return true;
}
//判断落子后自己是否有气
if (hasRoom(x, y, status, myLink, currentBoard)) {
currentBoard[x][y] = status;
dajie = false;
return true;
}
return false;
}
//局面 统计(有效边界值为1,私有空间值为4。允许重复统计)
static Point myCalculate(int[][] tempStatus, int myStatus, ArrayList<Point> rooms) {
//对手脏链
ArrayList<Point> enemySmear = new ArrayList<>();
//�
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Java语言写的围棋小游戏。半成品A Go game written in golang(Semi-finished).zip (27个子文件)
WeiQi-main
lib
kotlin-stdlib-jdk7-sources.jar 2KB
kotlin-stdlib-jdk8-sources.jar 6KB
kotlin-stdlib.jar 1.27MB
kotlin-test.jar 30KB
kotlin-reflect-sources.jar 698KB
kotlin-reflect.jar 2.74MB
kotlin-stdlib-jdk7.jar 3KB
kotlin-stdlib-sources.jar 423KB
kotlin-stdlib-jdk8.jar 15KB
kotlin-test-sources.jar 3KB
src
common
BeginGo.java 7KB
utils
StrategyUtil.java 13KB
ChessBoardUtil.java 7KB
Recursion.java 4KB
model
Atom.java 1KB
Coordinate.java 1KB
ConnectLink.java 8KB
constants
Constants.java 885B
out
production
WeiQi
common
BeginGo.class 5KB
utils
ChessBoardUtil.class 5KB
StrategyUtil.class 8KB
model
Atom.class 1KB
ConnectLink.class 6KB
Coordinate.class 1KB
constants
Constants.class 948B
Recursion.class 3KB
META-INF
application.xml 323B
共 27 条
- 1
资源评论
马coder
- 粉丝: 1208
- 资源: 6602
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 数据库基本概念 ,常用数据库,sql server数据库,Access数据库,sql语句,数据库连接,数据库分页显示
- VBScript脚本语言概述,VBScript的对象和事件
- 甜蜜约会网页制作html.docx
- Python插入排序.docx
- 瑞萨RZ/V2H 四核视觉 AI 处理器REN-r01ds0429ej0100-rzv2h-DST-20231224.pdf
- Simulink三相两电平逆变器
- cesium源码,直接解压放到vscode中运行就行
- smpl2bvh smpl pkl 数据转 fbx
- 3dmax打开gltf/glb插件,1.4.2版本
- 安卓app开发期末大作业的个记账工具APP.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功