ai.js
changeset 118 7e93fb8136a3
parent 110 e3a91b336976
child 122 4cc40a51742a
equal deleted inserted replaced
117:5701802ff232 118:7e93fb8136a3
   257     var bestDir;
   257     var bestDir;
   258     for (var i = 0; i < ai.dirs.length; i++) {
   258     for (var i = 0; i < ai.dirs.length; i++) {
   259         var dir = ai.dirs[i];
   259         var dir = ai.dirs[i];
   260         if (origBrd[dir](nextBrd)) {
   260         if (origBrd[dir](nextBrd)) {
   261             var weight = this.evalFn(nextBrd);
   261             var weight = this.evalFn(nextBrd);
   262             var ok = (weight - maxWeight) > this.cfg.weightPriority;
   262             var ok = (weight - maxWeight) > this.cfg.weightThreshold;
   263             if ( ! ok && maxWeight <= weight) {
   263             if ( ! ok && maxWeight <= weight) {
   264                 nextScore = this.weight(nextBrd);
   264                 nextScore = this.weight(nextBrd);
   265                 ok = prevScore < nextScore;
   265                 ok = prevScore < nextScore;
   266             }
   266             }
   267             if (ok) {
   267             if (ok) {
   319     if ( this.cfg.balance > 1)
   319     if ( this.cfg.balance > 1)
   320         this.cfg.balance = 1;
   320         this.cfg.balance = 1;
   321     if (!this.cfg.depth || this.cfg.depth < 0 || 8 <= this.cfg.depth)
   321     if (!this.cfg.depth || this.cfg.depth < 0 || 8 <= this.cfg.depth)
   322         this.cfg.depth = ai.expectimax.bestCfg.depth;
   322         this.cfg.depth = ai.expectimax.bestCfg.depth;
   323 }
   323 }
   324 ai.expectimax.bestCfg = {balance: .9, depth: 3, scoreCoef: 1, maxValCoef: 0, cornerBonus: 0, edgeBonus: 0, freeBonus: 0, weightPriority: 10};
   324 ai.expectimax.bestCfg = {balance: .9, depth: 3, scoreCoef: 1, maxValCoef: 0, cornerBonus: 0, edgeBonus: 0, freeBonus: 0, weightThreshold: 10};
   325 ai.expectimax.prototype.weight = function(brd) {
   325 ai.expectimax.prototype.weight = function(brd) {
   326     var score = 0;
   326     var score = 0;
   327     if (this.cfg.scoreCoef > 0)
   327     if (this.cfg.scoreCoef > 0)
   328         score += this.cfg.scoreCoef * brd.score();
   328         score += this.cfg.scoreCoef * brd.score();
   329     var max = brd.max();
   329     var max = brd.max();
   348     this.cleanup();
   348     this.cleanup();
   349     for (var i = 0; i < ai.dirs.length; i++) {
   349     for (var i = 0; i < ai.dirs.length; i++) {
   350         var dir = ai.dirs[i];
   350         var dir = ai.dirs[i];
   351         if (origBrd[dir](nextBrd)) {
   351         if (origBrd[dir](nextBrd)) {
   352             var weight = this.evalFn(nextBrd, 1);
   352             var weight = this.evalFn(nextBrd, 1);
   353             var ok = (weight - maxWeight) > this.cfg.weightPriority;
   353             var ok = (weight - maxWeight) > this.cfg.weightThreshold;
   354             if ( ! ok && maxWeight <= weight) {
   354             if ( ! ok && maxWeight <= weight) {
   355                 nextScore = this.weight(nextBrd);
   355                 nextScore = this.weight(nextBrd);
   356                 ok = prevScore < nextScore;
   356                 ok = prevScore < nextScore;
   357             }
   357             }
   358             if (ok) {
   358             if (ok) {