📄 life.h
字号:
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <mpi.h>
#include <stdio.h>
#include <malloc.h>
using namespace std; //命名空间
const int TIMELOOP=50; //最大迭代次数
const int ROW=50; //海域矩阵行数
const int COLUMN=20; //海域矩阵列数
const int FISH_LIFE_SPAN=10; //小鱼生命周期
const int FISH_BORN_AGE=3; //小鱼生育周期
const int SHARK_LIFE_SPAN=20; //鲨鱼生命周期
const int SHARK_STARVE_SPAN=5; //鲨鱼饥饿极限
const int SHARK_BORN_AGE=5; //鲨鱼生育周期
const int EMPTY=0; //空白区域类型
const int NOTHING_TO_EAT=-1; //鲨鱼没有食物
const int NOWHERE_TO_MOVE=-1; //没有方向移动
const int FISH_TYPE=1; //小鱼占据区域
const int SHARK_TYPE=2; //鲨鱼占据区域
const int MSG_FINISH=0; //处理结束消息
const int MSG_APPLICATION=1; //申请更改消息
const int MSG_AGREE=2; //同意申请消息
const int MSG_DISAGREE=3; //拒绝申请消息
const int MSG_UPDATE=4; //更新主进程数据消息
const int IN_WORKFIELD=0; //细胞在工作区
const int IN_UP_BOUNDARY=1; //细胞在上边界
const int IN_BOTTOM_BOUNDARY=2; //细胞在下边界
const int COLLIDE=0; //细胞行为冲突
const int CHANGED=-1; //细胞已经被修改过
const int SUCCEED=1; //细胞行为成功
const enum {RIGHT,DOWN,LEFT,UP}; //方向枚举类型
typedef struct Cell{ //细胞结构体
int Type; //细胞类型
int Age; //细胞年龄
int StarvationTime; //饥饿时间
} Cell;
typedef struct Msg{ //消息结构体
int Type; //消息类型
int Source; //消息来源
} Msg;
typedef struct CellNode{ //细胞节点结构类型
Cell* NodeElem; //细胞指针
int x; //细胞位置坐标
int y;
struct CellNode * next; //细胞链表指针
}CellNode;
void SeaInit(Cell &matrix,int rows,int cols);
void OutPutSea(Cell &matrix,int rows,int cols);
int GetCellListLen(struct CellNode *ListHead);
struct CellNode *InsertCellList(struct CellNode *ListHead,Cell* CellElem,int x,int y);
struct CellNode *CreatCellList(struct CellNode *ListHead,Cell &matrix,int rows,int cols,int TYPE);
void PrintList(struct CellNode *ListHead);
struct CellNode *GetCell(struct CellNode *ListHead);
int RandEatDiretion(Cell &matrix,int rows,int cols,int i,int j);
int RandMoveDiretion(Cell &matrix,int rows,int cols,int i,int j);
int EatFish(Cell &matrix,int rows,int cols,int i,int j,int EatDirection,MPI_Datatype MsgType,MPI_Datatype CellType);
void Move(Cell &matrix,int rows,int cols,int i,int j,int MoveDirection,MPI_Datatype MsgType,MPI_Datatype CellType);
void Action(struct CellNode* List,Cell &matrix,int rows,int cols,int TYPE,MPI_Datatype MsgType,MPI_Datatype CellType);
int InBoundary(int row,int x);
void DealApplication(Cell & GotData,int x,int y,int rank,MPI_Datatype MsgType,MPI_Datatype CellType);
void PosMap(int &x,int &y,int i,int j);
bool SelfCheck(Cell &matrix,int rows,int cols,int i,int j,Cell &Self);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -