资源简介
俄罗斯方块AI的C代码和设计文档
(包含调试信息的版本与不包含调试信息的版本)

代码片段和文件信息
// Tetris.cpp : 定义控制台应用程序的入口点。
//
//#include “stdafx.h“
#include “string.h“
#include “stdlib.h“
#include “stdio.h“
#include “time.h“
int const LINE=17;
int const WIDTH=10;
int HIGHLIMIT=6;
int SCORE;
typedef struct Status{
int xyOffset[4][2]; // block body based on base point xy
int curDrc; //direction
int side; // the leftest point x
Status *next;
}Status;
typedef struct Factor{
Status *status; //status of Block
int faces;
int fullLine;
int emptyCells;
int hight;
int realX; //coordinate of Block
int realY; //coordinate of Block
}Factor;
int Board[LINE+1][WIDTH];// Game board 17line*10width
int TempBoard[LINE+1][WIDTH];//Used to get board Status
Status * Block[8]; // 7 blocksblock list
//advanced array
int const AdvLength=20;// length of the array
int AdvBlocks[AdvLength]; //advanced blocks
int CurIndex; //current index of in the array
void PrintTempBoard()
{
//int minLine=GetTempBoard();
for(int i=0;i for(int j=0;j printf(“%c“TempBoard[i][j]?‘x‘:‘-‘);
printf(“\n“);
}
void PrintBoard()
{
for(int y=0;y for(int x=0;x printf(“%c“Board[LINE-y-1][x]?‘X‘:‘-‘);
}
void PrintBlock(Status block)
{
int xy[6][6]={0};
for(int i=0;i<4;i++)
{
printf(“(%d%d)\t“block.xyOffset[i][0]block.xyOffset[i][1]);
int x=block.xyOffset[i][0]+2;
int y=block.xyOffset[i][1]+2;
xy[x][y]=1;
}
printf(“\n“);
for(int i=5;i>=0;i--printf(“\n“))
for(int j=0;j<6;j++)
{
printf(“%c“xy[j][i]?‘X‘:‘-‘);
}
printf(“\n\n“);
}
/*
init the AdvBlocks array
*/
int containBlock(int block)
{
for(int i=0;i if(AdvBlocks[i]==block) return 1;
return 0;
}
void initAdvBlocks()
{
srand(time(NULL));
for(int i=0;i AdvBlocks[i]=rand()%7+1;
}
/*
get a new block
*/
int getNextBlock()
{
int temp=AdvBlocks[CurIndex];
//AdvBlocks[CurIndex]= containBlock(2)?rand()%7+1:2;
AdvBlocks[CurIndex]= rand()%7+1;
CurIndex=(CurIndex+1)%AdvLength;
//return rand()%2?5:7;
return temp;
}
/*
preview the next block
*/
int viewNextBlock()
{
return AdvBlocks[(CurIndex+1)%AdvLength];
}
/*
determine whether a cell is inside the board (Board / TempBoard)
*/
int insideBoard(int yint x)
{
return (y>=0 && y=0&& x }
/*
Get the TempBoard which is used to specify the empty space where the block can be put.
*/
void GetTempBoard()
{
memset(TempBoard1sizeof(TempBoard));
for(int x=0;x {
for(int y=LINE-1;y>=0;y--)
{
if(Board[y][x]) break;
TempBoard[y][x]=0;
}
}
//PrintTempBoard();
}
/*
Determine whether the block is fit into the TempBoard.
*/
int fitIn(Status * block int x int y)
{
for(int i=0;i<4;i++)
{
int realX=x+block->xyOffset[i][0];
int realY=y+block->xyOffset[i][1];
if(!insideBoard(realYreal
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 13335 2009-09-23 14:16 Tetris_Debug.cpp
文件 182390 2009-06-07 16:37 Design specification.docx
文件 12458 2009-06-01 16:43 Tetris_Sec.cpp
----------- --------- ---------- ----- ----
208183 3
- 上一篇:教学计划编制问题--课程管理
- 下一篇:UML案例:BBS系统一
相关资源
- 随机森林R语言代码
- 计算机图形学 边填充算法实现代码
- 直流无刷电机方波驱动 stm32 例程代码
- 仿知乎界面小程序源代码
- 贪吃蛇源代码.fla
- 周立功开发板ProASIC3实验-syn_FIFO代码
- IMX385驱动代码.zip
- dotnet 写字板 实验 源代码 不好请要不
- 图像二维小波变换的实现源代码
- 八三编码器设计 VHDL代码 简单,包附
- linux应用层的华容道游戏源代码
- 交通咨询模拟系统完整代码
- http请求状态代码
- 数值分析所有实验代码
- 网上拍卖系统完整源代码
- 音乐代码转换软件 单片机编程时用
- CSMA/CD等动画演示加源代码
- silicon lab公司的收音IC SI47XX全套开发工
- 用51单片机实现G代码翻译
- 合同管理系统的源代码(附数据库)
- 用VC 编写的仿QQ聊天室程序源代码
- web班级网站设计代码
- 38k单片机红外发送代码、keil
- STM32F103 串口程序(完整版)
- 网络唤醒代码
- VPC3_DPV1源代码,Profibus
- PB做的托盘程序(最小化后在左下角显
- RSA算法源码
- ubuntu9.10 可加载内核模块和字符设备驱
- 操作系统 LRU算法 实验报告 及 程序代
评论
共有 条评论