当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript path.init方法代码示例

本文整理汇总了TypeScript中tree.path.init方法的典型用法代码示例。如果您正苦于以下问题:TypeScript path.init方法的具体用法?TypeScript path.init怎么用?TypeScript path.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tree.path的用法示例。


在下文中一共展示了path.init方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: jumpToNext

 function jumpToNext(): void {
   feedback('find');
   const node = findNextNode();
   if (!node) {
     current(null);
     return redraw();
   }
   const fault = {
     node,
     path: root.mainlinePathToPly(node.ply)
   };
   const prevPath = treePath.init(fault.path);
   const prev = {
     node: root.tree.nodeAtPath(prevPath),
     path: prevPath
   };
   const solutionNode = prev.node.children.find(n => !!n.comp);
   current({
     fault,
     prev,
     solution: {
       node: solutionNode,
       path: prevPath + solutionNode!.id
     },
     openingUcis: []
   });
   // fetch opening explorer moves
   if (game.variant.key === 'standard' && game.division && (!game.division.middle || fault.node.ply < game.division.middle)) {
     root.explorer.fetchMasterOpening(prev.node.fen).then((res: OpeningData) => {
       const cur = current();
       const ucis: Uci[] = [];
       res!.moves.forEach(function(m) {
         if (m.white + m.draws + m.black > 1) ucis.push(m.uci);
       });
       if (ucis.find(function(uci) {
         return fault.node.uci === uci;
       })) {
         explorerCancelPlies.push(fault.node.ply);
         setTimeout(jumpToNext, 100);
       } else {
         cur.openingUcis = ucis;
         current(cur);
       }
     });
   }
   root.userJump(prev.path);
   redraw();
 };
开发者ID:ddugovic,项目名称:lila,代码行数:48,代码来源:retroCtrl.ts

示例2: initiate

  function initiate(fromData) {
    data = fromData;
    tree = treeBuild(treeOps.reconstruct(data.game.treeParts));
    var initialPath = treePath.fromNodeList(treeOps.mainlineNodeList(tree.root));
    // play | try | view
    vm.mode = 'play';
    vm.loading = false;
    vm.round = undefined;
    vm.voted = undefined;
    vm.justPlayed = undefined;
    vm.resultSent = false;
    vm.lastFeedback = 'init';
    vm.initialPath = initialPath;
    vm.initialNode = tree.nodeAtPath(initialPath);

    setPath(treePath.init(initialPath));
    setTimeout(function() {
      jump(initialPath);
      redraw();
    }, 500);

    // just to delay button display
    vm.canViewSolution = false;
    setTimeout(function() {
      vm.canViewSolution = true;
      redraw();
    }, 5000);

    moveTest = moveTestBuild(vm, data.puzzle);

    withGround(function(g) {
      g.setAutoShapes([]);
      g.setShapes([]);
      showGround(g);
    });

    instanciateCeval();

    history.replaceState(null, '', '/training/' + data.puzzle.id);
  };
开发者ID:ddugovic,项目名称:lila,代码行数:40,代码来源:ctrl.ts

示例3: checkCeval

 function checkCeval() {
   const node = root.node;
   if (!running()) {
     comment(null);
     return root.redraw();
   }
   if (tablebaseGuaranteed(variant, node.fen) && !defined(node.tbhit)) return;
   ensureCevalRunning();
   if (isMyTurn()) {
     const h = hinting();
     if (h) {
       h.uci = nodeBestUci(node) || h.uci;
       root.setAutoShapes();
     }
   } else {
     comment(null);
     if (node.san && commentable(node)) {
       const parentNode = root.tree.parentNode(root.path);
       if (commentable(parentNode, +1)) comment(makeComment(parentNode, node, root.path));
       else {
         /*
          * Looks like the parent node didn't get enough analysis time
          * to be commentable :-/ it can happen if the player premoves
          * or just makes a move before the position is sufficiently analysed.
          * In this case, fall back to comparing to the position before,
          * Since computer moves are supposed to preserve eval anyway.
          */
         const olderNode = root.tree.parentNode(treePath.init(root.path));
         if (commentable(olderNode, +1)) comment(makeComment(olderNode, node, root.path));
       }
     }
     if (!played() && playable(node)) {
       root.playUci(nodeBestUci(node)!);
       played(true);
     } else root.redraw();
   }
 };
开发者ID:ddugovic,项目名称:lila,代码行数:37,代码来源:practiceCtrl.ts

示例4: make

export function make(root: AnalyseCtrl, playableDepth: () => number): PracticeCtrl {

  const running = prop(true),
  comment = prop<Comment | null>(null),
  hovering = prop<any>(null),
  hinting = prop<any>(null),
  played = prop(false);

  function ensureCevalRunning() {
    if (!root.showComputer()) root.toggleComputer();
    if (!root.ceval.enabled()) root.toggleCeval();
    if (root.threatMode()) root.toggleThreatMode();
  }

  function commentable(node: Tree.Node, bonus: number = 0): boolean {
    if (root.gameOver(node)) return true;
    const ceval = node.ceval;
    return ceval ? ((ceval.depth + bonus) >= 15 || (ceval.depth >= 13 && ceval.millis > 3000)) : false;
  }

  function playable(node: Tree.Node): boolean {
    const ceval = node.ceval;
    return ceval ? (
      ceval.depth >= Math.min(ceval.maxDepth || 99, playableDepth()) ||
      (ceval.depth >= 15 && ceval.millis > 5000)
    ) : false;
  };

  const altCastles = {
    e1a1: 'e1c1',
    e1h1: 'e1g1',
    e8a8: 'e8c8',
    e8h8: 'e8g8'
  };

  function makeComment(prev, node: Tree.Node, path: Tree.Path): Comment {
    let verdict, best;
    const over = root.gameOver(node);

    if (over === 'checkmate') verdict = 'good';
    else {
      const nodeEval: Eval = (node.threefold || over === 'draw') ? {
        cp: 0
      } : (node.ceval as Eval);
      const shift = -winningChances.povDiff(root.bottomColor(), nodeEval, prev.ceval);

      best = prev.ceval.pvs[0].moves[0];
      if (best === node.uci || best === altCastles[node.uci]) best = null;

      if (!best) verdict = 'good';
      else if (shift < 0.025) verdict = 'good';
      else if (shift < 0.06) verdict = 'inaccuracy';
      else if (shift < 0.14) verdict = 'mistake';
      else verdict = 'blunder';
    }

    return {
      prev,
      node,
      path,
      verdict,
      best: best ? {
        uci: best,
        san: pv2san(root.data.game.variant.key, prev.fen, false, [best])
      } : undefined
    };
  }

  function isMyTurn(): boolean {
    return root.turnColor() === root.bottomColor();
  };

  function checkCeval() {
    const node = root.node;
    if (!running()) {
      comment(null);
      return root.redraw();
    }
    ensureCevalRunning();
    if (isMyTurn()) {
      const h = hinting();
      if (h && node.ceval) {
        h.uci = node.ceval.pvs[0].moves[0];
        root.setAutoShapes();
      }
    } else {
      comment(null);
      if (node.san && commentable(node)) {
        const parentNode = root.tree.parentNode(root.path);
        if (commentable(parentNode, +1)) comment(makeComment(parentNode, node, root.path));
        else {
          /*
           * Looks like the parent node didn't get enough analysis time
           * to be commentable :-/ it can happen if the player premoves
           * or just makes a move before the position is sufficiently analysed.
           * In this case, fall back to comparing to the position before,
           * Since computer moves are supposed to preserve eval anyway.
           */
          const olderNode = root.tree.parentNode(treePath.init(root.path));
          if (commentable(olderNode, +1)) comment(makeComment(olderNode, node, root.path));
//.........这里部分代码省略.........
开发者ID:lexisvar,项目名称:lila,代码行数:101,代码来源:practiceCtrl.ts

示例5: prev

export function prev(ctrl) {
  ctrl.userJump(treePath.init(ctrl.vm.path));
}
开发者ID:ddugovic,项目名称:lila,代码行数:3,代码来源:control.ts

示例6: setTimeout

 setTimeout(function() {
   withGround(function(g) { g.cancelPremove(); });
   userJump(treePath.init(vm.path));
   redraw();
 }, 500);
开发者ID:ddugovic,项目名称:lila,代码行数:5,代码来源:ctrl.ts

示例7: prev

export function prev(ctrl: AnalyseCtrl): void {
  ctrl.userJumpIfCan(treePath.init(ctrl.path));
}
开发者ID:ddugovic,项目名称:lila,代码行数:3,代码来源:control.ts


注:本文中的tree.path.init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。