为AI类以及其涉及到的其他类的函数进行注释

This commit is contained in:
shijian 2023-12-20 23:34:17 +08:00
parent f7495db4b2
commit f9a111dc8b
7 changed files with 102 additions and 53 deletions

View File

@ -47,10 +47,7 @@ new Promise(resolve => {
/**
* @type { Promise<import('../noname.js')> }
*
* game.js不是一个模块所以导入的路径是从html文件开始算起的
*/
// @ts-ignore
const module = import('../noname.js');
module.then(({ ai, game, get, lib, _status, ui }) => {

View File

@ -7,11 +7,17 @@ import { GNC as gnc } from '../gnc/index.js';
import { Uninstantable } from "../util/index.js";
export class Basic extends Uninstantable {
/**
* @param { (
* button: import('../library/index.js').Button,
* buttons?: import('../library/index.js').Button[]
* ) => number } check
*/
static chooseButton(check) {
var event = _status.event;
var i, j, range, buttons, buttons2;
var ok = false, forced = event.forced;
var iwhile = 100;
const event = _status.event;
let i, j, range, buttons, buttons2;
let ok = false, forced = event.forced;
let iwhile = 100;
while (iwhile--) {
range = get.select(event.selectButton);
if (ui.selected.buttons.length >= range[0]) {
@ -29,10 +35,10 @@ export class Basic extends Uninstantable {
return ok;
}
buttons2 = buttons.slice(0);
var ix = 0;
var checkix = check(buttons[0], buttons2);
let ix = 0;
let checkix = check(buttons[0], buttons2);
for (i = 1; i < buttons.length; i++) {
var checkixtmp = check(buttons[i], buttons2);
let checkixtmp = check(buttons[i], buttons2);
if (checkixtmp > checkix) {
ix = i;
checkix = checkixtmp;
@ -57,12 +63,19 @@ export class Basic extends Uninstantable {
}
}
}
/**
* @param { (
* card?: import('../library/index.js').Card,
* cards?: import('../library/index.js').Card[]
* ) => number } check
* @returns { boolean | undefined }
*/
static chooseCard(check) {
var event = _status.event;
const event = _status.event;
if (event.filterCard == undefined) return (check() > 0);
var i, j, range, cards, cards2, skills, check, effect;
var ok = false, forced = event.forced;
var iwhile = 100;
let i, j, range, cards, cards2, skills, effect;
let ok = false, forced = event.forced;
let iwhile = 100;
while (iwhile--) {
range = get.select(event.selectCard);
if (ui.selected.cards.length >= range[0]) {
@ -80,6 +93,7 @@ export class Basic extends Uninstantable {
}
cards = get.selectableCards();
if (!_status.event.player._noSkill) {
// @ts-ignore
cards = cards.concat(get.skills());
}
if (cards.length == 0) {
@ -127,12 +141,18 @@ export class Basic extends Uninstantable {
}
}
}
/**
* @param { (
* target?: import('../library/index.js').Player,
* targets?: import('../library/index.js').Player[]
* ) => number } check
*/
static chooseTarget(check) {
var event = _status.event;
const event = _status.event;
if (event.filterTarget == undefined) return (check() > 0);
var i, j, range, targets, targets2, effect;
var ok = false, forced = event.forced;
var iwhile = 100;
let i, j, range, targets, targets2, effect;
let ok = false, forced = event.forced;
let iwhile = 100;
while (iwhile--) {
range = get.select(event.selectTarget);
if (ui.selected.targets.length >= range[0]) {
@ -158,10 +178,10 @@ export class Basic extends Uninstantable {
// targets.sort(function(a,b){
// return check(b)-check(a);
// });
var ix = 0;
var checkix = check(targets[0], targets2);
let ix = 0;
let checkix = check(targets[0], targets2);
for (i = 1; i < targets.length; i++) {
var checkixtmp = check(targets[i], targets2);
let checkixtmp = check(targets[i], targets2);
if (checkixtmp > checkix) {
ix = i;
checkix = checkixtmp;

View File

@ -11,14 +11,17 @@ export class Game extends Uninstantable {
static onlineID = null;
static onlineKey = null;
/**
* @type {Player[]}
* @type {import('../library/index.js').Player[]}
*/
static players = [];
/**
* @type {Player[]}
* @type {import('../library/index.js').Player[]}
*/
static dead = [];
static imported = [];
/**
* @type { { [key: string]: import('../library/index.js').Player } }
*/
static playerMap = {};
static phaseNumber = 0;
static roundNumber = 0;

View File

@ -1832,12 +1832,17 @@ export class Get extends Uninstantable {
return Math.sqrt(dx * dx + dy * dy);
}
static xyDistance(from, to) { return Math.sqrt((from[0] - to[0]) * (from[0] - to[0]) + (from[1] - to[1]) * (from[1] - to[1])) }
/**
* @param { [number, number] | string | import('../library/index.js').Player[] |
* import('../library/index.js').Card[] | [number, number, number, number] | import('../library/index.js').Button |
* import('../library/index.js').Dialog | import('../library/index.js').Player | import('../library/index.js').Card |
* import('../library/index.js').GameEvent | import('../library/index.js').GameEventPromise } obj
*/
static itemtype(obj) {
var i, j;
if (typeof obj == 'string') {
if (obj.length <= 5) {
var bool = true;
for (i = 0; i < obj.length; i++) {
let bool = true;
for (let i = 0; i < obj.length; i++) {
if (/h|e|j|s|x/.test(obj[i]) == false) {
bool = false; break;
}
@ -1847,18 +1852,13 @@ export class Get extends Uninstantable {
if (obj.includes(lib.natureSeparator) && obj.split(lib.natureSeparator).every(n => lib.nature.has(n))) return 'natures';
if (lib.nature.has(obj)) return 'nature';
}
if (Array.isArray(obj) && obj.length) {
var isPlayers = true;
for (i = 0; i < obj.length; i++) {
if (get.itemtype(obj[i]) != 'player') { isPlayers = false; break; }
if (Array.isArray(obj) && obj.length > 0) {
if (obj.every(p => p instanceof lib.element.Player)) {
return 'players';
}
if (isPlayers) return 'players';
var isCards = true;
for (i = 0; i < obj.length; i++) {
if (get.itemtype(obj[i]) != 'card') { isCards = false; break; }
if (obj.every(p => p instanceof lib.element.Card)) {
return 'cards';
}
if (isCards) return 'cards';
if (obj.length == 2) {
if (typeof obj[0] == 'number' && typeof obj[1] == 'number') {
@ -1867,22 +1867,17 @@ export class Get extends Uninstantable {
}
if (obj.length == 4) {
var isPosition = true;
for (i = 0; i < obj.length; i++) {
if (typeof obj[i] != 'number') { isPosition = false; break; }
if (obj.every(p => typeof p == 'number')) {
return 'divposition';
}
if (isPosition) return 'divposition';
}
}
if (get.objtype(obj) == 'div') {
if (obj.classList.contains('button')) return 'button';
if (obj.classList.contains('card')) return 'card';
if (obj.classList.contains('player')) return 'player';
if (obj.classList.contains('dialog')) return 'dialog';
}
if (get.is.object(obj)) {
if (obj.isMine == lib.element.GameEvent.prototype.isMine) return 'event';
}
if (obj instanceof lib.element.Button) return 'button';
if (obj instanceof lib.element.Card) return 'card';
if (obj instanceof lib.element.Player) return 'player';
if (obj instanceof lib.element.Dialog) return 'dialog';
if (obj instanceof lib.element.GameEvent ||
obj instanceof lib.element.GameEventPromise) return 'event';
}
static equipNum(card) {
if (get.type(card) == 'equip') {
@ -2172,11 +2167,16 @@ export class Get extends Uninstantable {
return lib.card[name];
}
}
/**
* @param { number | [number, number] | (()=>[number, number]) } [select]
* @returns { [number, number] }
*/
static select(select) {
if (typeof select == 'number') return [select, select];
// @ts-ignore
if (get.itemtype(select) == 'select') return select;
if (typeof select == 'function') return get.select(select());
return [1, 1]
return [1, 1];
}
static card(original) {
if (_status.event.skill) {
@ -2428,6 +2428,10 @@ export class Get extends Uninstantable {
result = handleZero(result);
return result;
}
/**
* @param {((a: import('../library/index.js').Button, b: import('../library/index.js').Button) => number)} [sort] 排序函数
* @returns { import('../library/index.js').Button[] }
*/
static selectableButtons(sort) {
if (!_status.event.player) return [];
var buttons = _status.event.dialog.buttons;
@ -2443,6 +2447,10 @@ export class Get extends Uninstantable {
}
return selectable;
}
/**
* @param {((a: import('../library/index.js').Card, b: import('../library/index.js').Card) => number)} [sort] 排序函数
* @returns { import('../library/index.js').Card[] }
*/
static selectableCards(sort) {
if (!_status.event.player) return [];
var cards = _status.event.player.getCards('hes');
@ -2458,6 +2466,9 @@ export class Get extends Uninstantable {
}
return selectable;
}
/**
* @returns { string[] } 技能名数组
*/
static skills() {
var skills = [];
if (ui.skills) {
@ -2532,6 +2543,10 @@ export class Get extends Uninstantable {
}
return list;
}
/**
* @param {((a: import('../library/index.js').Player, b: import('../library/index.js').Player) => number)} [sort] 排序函数
* @returns { import('../library/index.js').Player[] }
*/
static selectableTargets(sort) {
var selectable = [];
var players = game.players.slice(0);

View File

@ -2,6 +2,8 @@
* @typedef {InstanceType<typeof lib.element.Player>} Player
* @typedef {InstanceType<typeof lib.element.Card>} Card
* @typedef {InstanceType<typeof lib.element.VCard>} VCard
* @typedef {InstanceType<typeof lib.element.Button>} Button
* @typedef {InstanceType<typeof lib.element.Dialog>} Dialog
* @typedef {InstanceType<typeof lib.element.GameEvent>} GameEvent
* @typedef {InstanceType<typeof lib.element.GameEventPromise>} GameEventPromise
* @typedef {InstanceType<typeof lib.element.NodeWS>} NodeWS
@ -32105,7 +32107,7 @@ export class Library extends Uninstantable {
/**
* 事件转为Promise化
*
* @returns { Promise<GameEvent> & GameEvent & GameEventPromise }
* @returns { Promise<GameEvent> & GameEvent & GameEventPromise<> }
*/
toPromise() {
if (!this.#promise) {

View File

@ -6,8 +6,9 @@ export const status = {
clicked: false,
auto: false,
/**
* @type {GameEvent}
* @type {import('../library/index.js').GameEventPromise & import('../library/index.js').GameEvent}
*/
// @ts-ignore
event: null,
ai: {},
lastdragchange: [],

View File

@ -14001,7 +14001,18 @@ export class UI extends Uninstantable {
static create = Create;
static click = Click;
static selected = {
buttons: [], cards: [], targets: []
/**
* @type { import('../library/index.js').Button[]}
*/
buttons: [],
/**
* @type { import('../library/index.js').Card[]}
*/
cards: [],
/**
* @type { import('../library/index.js').Player[]}
*/
targets: []
}
static refresh(node) {
void window.getComputedStyle(node, null).getPropertyValue("opacity");