Skip to content

Commit

Permalink
fix step bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lihongxun945 committed Jul 11, 2018
1 parent e944c9e commit fcc06c3
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ai/negamax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/views/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
68 changes: 67 additions & 1 deletion tests/unit/AI.time.spec.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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);
});
})

0 comments on commit fcc06c3

Please sign in to comment.