中国象棋游戏,可以vs电脑,vs人,网络对战没有,界面是最简单的可以更改draw函数达到华丽的效果,ai是最初级的,我相信只要会点象棋的人就可以赢了我写的ai!这个确实应该改进使ai至少能赢了新手才好,希望以后有机会能实现了更高级别的ai,flash的博弈树做的太复杂了,对作者来说难度太大。
- package
- {
-
- /**
- * ...
- * @author sliz
- */
- public class AI
- {
- private var _chessboard:Chessboard;
- public function AI(cb:Chessboard)
- {
- _chessboard = cb;
- }
- public function doAi():Piece {
- var pieces:Array =new Array();
- for (var i:int = 0; i <= _chessboard._area.y2;i++ ) {
- for (var j:int = 0; j <= _chessboard._area.x2;j++ ) {
- if (_chessboard.getPiece(i, j)&&_chessboard.getPiece(i,j)._camp==true) {
- pieces.push(_chessboard.getPiece(i,j));
- }
- }
- }
- var checks:Array;
- var piece:Piece;
- while (pieces.length != 0) {
- checks = [];
- piece = pieces.splice(int(Math.random() * pieces.length), 1)[0];
- for (i = 0; i <= _chessboard._area.y2;i++ ) {
- for (j = 0; j <= _chessboard._area.x2;j++ ) {
- if (piece.check(j,i)) {
- checks.push({y:i,x:j});
- }
- }
- }
- if (checks.length!=0) {
- var p:Object = checks.splice(int(Math.random() * checks.length), 1)[0];
- piece.x = p.x * _chessboard._hg;
- piece.y = p.y * _chessboard._vg;
- return piece;
- }
- }
- return new Piece(_chessboard, { }, true);
- }
- }
-
- }
附件下载: