forked from Viscoo/gobang-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
785d51c
commit d715ca8
Showing
11 changed files
with
190 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
var R = require("./role.js"); | ||
var isFive = function(board, p, role) { | ||
var len = board.length; | ||
var count = 0; | ||
|
||
var reset = function() { | ||
count = 0; | ||
} | ||
|
||
for(var i=p[1]+1;true;i++) { | ||
if(i>=len) break; | ||
var t = board[p[0]][i]; | ||
if(t !== role) break; | ||
count ++; | ||
} | ||
|
||
|
||
for(var i=p[1]-1;true;i--) { | ||
if(i<0) break; | ||
var t = board[p[0]][i]; | ||
if(t !== role) break; | ||
count ++; | ||
} | ||
|
||
if(count >= 5) return true; | ||
|
||
//纵向 | ||
reset(); | ||
|
||
for(var i=p[0]+1;true;i++) { | ||
if(i>=len) { | ||
break; | ||
} | ||
var t = board[i][p[1]]; | ||
if(t !== role) break; | ||
count ++; | ||
} | ||
|
||
for(var i=p[0]-1;true;i--) { | ||
if(i<0) { | ||
block ++; | ||
} | ||
var t = board[i][p[1]]; | ||
if(t !== role) break; | ||
count ++; | ||
} | ||
|
||
|
||
if(count >= 5) return true; | ||
// \\ | ||
reset(); | ||
|
||
for(var i=1;true;i++) { | ||
var x = p[0]+i, y = p[1]+i; | ||
if(x>=len || y>=len) { | ||
break; | ||
} | ||
var t = board[x][y]; | ||
if(t !== role) break; | ||
|
||
count ++; | ||
} | ||
|
||
for(var i=1;true;i++) { | ||
var x = p[0]-i, y = p[1]-i; | ||
if(x<0||y<0) { | ||
break; | ||
} | ||
var t = board[x][y]; | ||
if(t !== role) break; | ||
count ++; | ||
} | ||
|
||
if(count >= 5) return true; | ||
|
||
// \/ | ||
reset(); | ||
|
||
for(var i=1; true;i++) { | ||
var x = p[0]+i, y = p[1]-i; | ||
if(x<0||y<0||x>=len||y>=len) { | ||
break; | ||
} | ||
var t = board[x][y]; | ||
if(t !== role) break; | ||
count ++; | ||
} | ||
|
||
for(var i=1;true;i++) { | ||
var x = p[0]-i, y = p[1]+i; | ||
if(x<0||y<0||x>=len||y>=len) { | ||
break; | ||
} | ||
var t = board[x][y]; | ||
if(t !== role) break; | ||
count ++; | ||
} | ||
|
||
if(count >= 5) return true; | ||
|
||
return false; | ||
|
||
} | ||
|
||
|
||
var w = function(board) { | ||
for(var i=0;i<board.length;i++) { | ||
for(var j=0;j<board[i].length;j++) { | ||
var t = board[i][j]; | ||
if(t !== R.empty) { | ||
if(isFive(board, [i, j], t)) return t; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
module.exports = w; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ | |
"test-checkmate": "mocha tests/test-checkmate.js", | ||
"test-m": "mocha tests/test-max-min.js", | ||
"test-evaluate-point": "mocha tests/test-evaluate-point.js", | ||
"test-zobrist": "mocha tests/test-zobrist.js" | ||
"test-zobrist": "mocha tests/test-zobrist.js", | ||
"test-win": "mocha tests/test-win.js" | ||
}, | ||
"author": "Hongxun Lee <[email protected]> (http://light7.org/)", | ||
"homepage": "http://gobang.light7.cn/", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.