import { board } from "./board"; import { util } from "./util"; export declare namespace rule { interface Order { /** * The unit of Diplomacy that corresponds to this order. */ unit: board.Unit; } interface OrderResult { /** * The target order. */ target: Order; /** * The result of the target. */ result: Result; } /** * Result of an order execution. */ class Executed implements OrderResult { target: Order; result: Result; /** * @param target The target order. * @param result The result of the target. */ constructor(target: Order, result: Result); } /** * Result of an order execution. It is used when the original order is replaced. */ class Replaced implements OrderResult { target: Order; invalidReason: Error; replacedBy: Order; result: Result; /** * @param target The target order. * @param result The result of the target. * @param invalidReason The reason why the target is replaced * @param replacedBy The order that replaces the target. */ constructor(target: Order, invalidReason: Error, replacedBy: Order, result: Result); } class ResolvedResult { board: board.Board; isFinished: boolean; /** * The set of order results */ results: Set>; /** * @param board * @param results The set of order results * @param isFinished The flag whether this game is finished or not. */ constructor(board: board.Board, results: Set> | Array>, isFinished: boolean); } /** * Rule of Diplomacy */ abstract class Rule { /** * Resolves orders and creates a result. * @param board * @param orders The set of orders to be resolved. * @return The result of the orders */ resolve(board: board.Board, orders: Set>): util.ResultOrFail>; /** * @return The set of units that are requred orders. */ protected abstract unitsRequiringOrder(board: board.Board): Set>; /** * @return The default order of the unit. If there are no default order, it's null. */ protected abstract defaultOrderOf(board: board.Board, unit: board.Unit): Order | null; /** * @return The error message of the order. If the order is valid, it's null. */ protected abstract errorOfOrder(board: board.Board, order: Order): Error | null; /** * @return The error message of the orders. If the set of the orders is valid, it's null. */ protected abstract errorOfOrders(board: board.Board, orders: Set>): Error | null; /** * Resolve the orders, and creates result * @return The result of the orders. */ protected abstract resolveProcedure(board: board.Board, orders: Set>): util.ResultOrFail>; } }