feat: 实现麻将游戏结算系统与自摸胡功能
新增结算类型枚举和分数变更记录模型 补全响应裁决器与结算服务,支持点炮胡、自摸胡和明杠结算 扩展座位模型,增加已胡状态和分数字段 完善胡牌评估器,支持自摸胡判断 前端原型页增加分数显示和已胡状态 更新SPRINT文档记录当前进度
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.xuezhanmaster.game.service;
|
||||
|
||||
import com.xuezhanmaster.game.domain.ActionType;
|
||||
import com.xuezhanmaster.game.domain.ResponseActionResolution;
|
||||
import com.xuezhanmaster.game.domain.ResponseActionWindow;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class ResponseActionResolver {
|
||||
|
||||
public Optional<ResponseActionResolution> resolve(ResponseActionWindow window, Map<Integer, ActionType> selections, int seatCount) {
|
||||
return selections.entrySet().stream()
|
||||
.filter(entry -> entry.getValue() != ActionType.PASS)
|
||||
.min(Comparator
|
||||
.comparingInt((Map.Entry<Integer, ActionType> entry) -> priority(entry.getValue()))
|
||||
.thenComparingInt(entry -> seatDistance(window.sourceSeatNo(), entry.getKey(), seatCount)))
|
||||
.map(entry -> new ResponseActionResolution(
|
||||
entry.getValue(),
|
||||
entry.getKey(),
|
||||
window.sourceSeatNo(),
|
||||
window.triggerTile()
|
||||
));
|
||||
}
|
||||
|
||||
private int priority(ActionType actionType) {
|
||||
return switch (actionType) {
|
||||
case HU -> 0;
|
||||
case GANG -> 1;
|
||||
case PENG -> 2;
|
||||
case PASS -> 3;
|
||||
default -> 99;
|
||||
};
|
||||
}
|
||||
|
||||
private int seatDistance(int sourceSeatNo, int targetSeatNo, int seatCount) {
|
||||
return (targetSeatNo - sourceSeatNo + seatCount) % seatCount;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user