diff --git a/src/ai/negamax.js b/src/ai/negamax.js index 51b00cd..a9e7b5a 100644 --- a/src/ai/negamax.js +++ b/src/ai/negamax.js @@ -41,7 +41,7 @@ var negamax = function(deep, alpha, beta) { var p = candidates[i] board.put(p, R.com) var steps = [p[0], p[1]] - var v = r(deep-1, -beta, -alpha, R.hum, 2, steps.slice(0), 0) + var v = r(deep-1, -beta, -alpha, R.hum, 1, steps.slice(0), 0) v.score *= -1 alpha = Math.max(alpha, v.score) board.remove(p) diff --git a/src/views/home.js b/src/views/home.js index f7900b5..5ae131c 100644 --- a/src/views/home.js +++ b/src/views/home.js @@ -37,11 +37,11 @@ export default { this._set(position, 1) this.$store.dispatch(SET_STATUS, STATUS.PLAYING) - if (score >= SCORE.FIVE/2 && step <= 2) { + if (score >= SCORE.FIVE/2 && step <= 1) { this.$store.dispatch(SET_FIVES, win(this.board)) this.$store.dispatch(SET_STATUS, STATUS.LOCKED) this.showBigText(this.$t('you lose'), this.end) - } else if (score <= - SCORE.FIVE/2 && step <= 2) { + } else if (score <= - SCORE.FIVE/2 && step <= 1) { this.$store.dispatch(SET_FIVES, win(this.board)) this.$store.dispatch(SET_STATUS, STATUS.LOCKED) this.showBigText(this.$t('you win'), this.end) diff --git a/tests/unit/AI.time.spec.js b/tests/unit/AI.time.spec.js index 3b1c4bd..8206ca9 100644 --- a/tests/unit/AI.time.spec.js +++ b/tests/unit/AI.time.spec.js @@ -1,4 +1,4 @@ -import { expect } from 'chai' +import { expect, assert } from 'chai' import board from '@/ai/board.js' import Search from '@/ai/negamax.js' @@ -52,4 +52,70 @@ describe('Test Time', () => { expect(p.score <= - SCORE.FIVE/2).to.be.true }) + + it(`此处有杀棋, 只有 [6, 5], [5, 4] 两种走法有杀棋`, function() { + const b = [ + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 2, 1, 2, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + ]; + board.init(b); + var p = Search(10); + console.log("######", p); + assert.ok(p.score > 1500); + assert.ok((p[0] == 6 && p[1] === 5) || (p[0] == 5 && p[1] === 4)); + }); + it(`测试vct bug,此处应该没有杀棋`, function() { + const b = [ + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 2, 1, 2, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + ]; + board.init(b); + console.log(board.gen()) + var p = Search(); + console.log("######", p); + assert.ok(p.score < 2000); + }); + it(`测试冲四活三bug`, function() { + const b = [ + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 2, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 2, 1, 1, 1, 1, 2, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 2, 1, 2, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 2, 2, 1, 0, 2, 2, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + ]; + board.init(b); + console.log(board.gen()) + var p = Search(); + console.log("######", p); + // 冲四活三 + assert.ok(p.score > 2000); + }); })