• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript tree.path类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: function

  return function() {

    if (vm.mode === 'view') return;
    if (!pathOps.contains(vm.path, vm.initialPath)) return;

    var playedByColor = vm.node.ply % 2 === 1 ? 'white' : 'black';
    if (playedByColor !== puzzle.color) return;

    var nodes = vm.nodeList.slice(pathOps.size(vm.initialPath) + 1).map(function(node) {
      return {
        uci: node.uci,
        castle: node.san.startsWith('O-O')
      };
    });

    var progress = puzzle.lines;
    for (var i in nodes) {
      if (progress[nodes[i].uci]) progress = progress[nodes[i].uci];
      else if (nodes[i].castle) progress = progress[altCastles[nodes[i].uci]] || 'fail';
      else progress = 'fail';
      if (typeof progress === 'string') break;
    }
    if (typeof progress === 'string') {
      vm.node.puzzle = progress;
      return progress;
    }

    var nextKey = Object.keys(progress)[0]
      if (progress[nextKey] === 'win') {
        vm.node.puzzle = 'win';
        return 'win';
      }

      // from here we have a next move

      vm.node.puzzle = 'good';

    var opponentUci = decomposeUci(nextKey);
    var promotion = opponentUci[2] ? sanToRole[opponentUci[2].toUpperCase()] : null;

    var move: any = {
      orig: opponentUci[0],
      dest: opponentUci[1],
      fen: vm.node.fen,
      path: vm.path
    };
    if (promotion) move.promotion = promotion;

    return move;
  };
开发者ID:ornicar,项目名称:lila,代码行数:50,代码来源:moveTest.ts


示例2: throttle

 var getDests = throttle(800, function() {
   if (!vm.node.dests && treePath.contains(vm.path, vm.initialPath))
     socket.sendAnaDests({
       fen: vm.node.fen,
       path: vm.path
     });
 });
开发者ID:ddugovic,项目名称:lila,代码行数:7,代码来源:ctrl.ts


示例3: h

 return h('lines', nodes.map(n => {
   return retroLine(ctx, n, opts) || h('line', renderMoveAndChildrenOf(ctx, n, {
     parentPath: opts.parentPath,
     isMainline: false,
     withIndex: true,
     truncate: n.comp && !treePath.contains(ctx.ctrl.path, opts.parentPath + n.id) ? 3 : undefined
   }));
 }));
开发者ID:ddugovic,项目名称:lila,代码行数:8,代码来源:inlineView.ts


示例4: nodeClasses

export function nodeClasses(ctx: Ctx, path: Tree.Path): NodeClasses {
  return {
    active: path === ctx.ctrl.path,
    context_menu: path === ctx.ctrl.contextMenuPath,
    current: path === ctx.currentPath,
    nongame: !ctx.currentPath && !!ctx.ctrl.gamePath && treePath.contains(path, ctx.ctrl.gamePath) && path !== ctx.ctrl.gamePath
  };
}
开发者ID:ddugovic,项目名称:lila,代码行数:8,代码来源:treeView.ts


示例5: nodeClasses

export function nodeClasses(c: AnalyseCtrl, path: Tree.Path): NodeClasses {
  const current = (path === c.initialPath && game.playable(c.data)) || (
    c.retro && c.retro.current() && c.retro.current().prev.path === path
  );
  return {
    active: path === c.path,
    context_menu: path === c.contextMenuPath,
    current,
    nongame: !current && !!c.gamePath && treePath.contains(path, c.gamePath) && path !== c.gamePath
  };
}
开发者ID:lexisvar,项目名称:lila,代码行数:11,代码来源:treeView.ts


示例6: 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


示例7: 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


示例8: function


//.........这里部分代码省略.........
  function isWriting(): boolean {
    return vm.mode.write && !isGamebookPlay();
  }

  function makeChange(t: string, d: any): boolean {
    if (isWriting()) {
      send(t, d);
      return true;
    }
    return vm.mode.sticky = false;
  };

  const commentForm = commentFormCtrl(ctrl);
  const glyphForm = glyphFormCtrl(ctrl);
  const tags = tagsCtrl(ctrl, () => data.chapter, tagTypes);
  const desc = new ChapterDescriptionCtrl(data.chapter.description, t => {
    data.chapter.description = t;
    send("descChapter", {
      id: vm.chapterId,
      description: t
    });
  }, redraw);

  function addChapterId(req) {
    req.ch = vm.chapterId;
    return req;
  }

  function isGamebookPlay() {
    return data.chapter.gamebook && vm.gamebookOverride !== 'analyse' &&
    (vm.gamebookOverride === 'play' || !members.canContribute());
  }

  if (vm.mode.sticky && !isGamebookPlay()) ctrl.userJump(data.position.path);

  function configureAnalysis() {
    if (ctrl.embed) return;
    const canContribute = members.canContribute();
    // unwrite if member lost priviledges
    vm.mode.write = vm.mode.write && canContribute;
    li.pubsub.emit('chat.writeable')(data.features.chat);
    li.pubsub.emit('chat.permissions')({local: canContribute});
    const computer: boolean = !isGamebookPlay() && !!(data.chapter.features.computer || data.chapter.practice);
    if (!computer) ctrl.getCeval().enabled(false);
    ctrl.getCeval().allowed(computer);
    if (!data.chapter.features.explorer) ctrl.explorer.disable();
    ctrl.explorer.allowed(data.chapter.features.explorer);
  };
  configureAnalysis();

  function configurePractice() {
    if (!data.chapter.practice && ctrl.practice) ctrl.togglePractice();
    if (data.chapter.practice) ctrl.restartPractice();
    if (practice) practice.onReload();
  };

  function onReload(d: ReloadData) {
    const s = d.study!;
    const prevPath = ctrl.path;
    const sameChapter = data.chapter.id === s.chapter.id;
    vm.mode.sticky = (vm.mode.sticky && s.features.sticky) || (!data.features.sticky && s.features.sticky);
    if (vm.mode.sticky) vm.behind = 0;
    if (vm.mode.sticky && s.position !== data.position) commentForm.close();
    'position name visibility features settings chapter likes liked'.split(' ').forEach(key => {
      data[key] = s[key];
    });
开发者ID:lexisvar,项目名称:lila,代码行数:67,代码来源:studyCtrl.ts


示例9: 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


示例10: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript try-resolve.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript tree.ops类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap