proc节点技巧

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <linux/pnp.h>
#include <linux/seq_file.h>
#include <linux/init.h>

#include <asm/uaccess.h>

static struct proc_dir_entry *proc_pnp = NULL;

#define MAX_PORT 11
static int proc_open(struct inode *inode, struct file *file)
{
	printk("proc_open\n");
	return 0;
}



static const struct file_operations proc_fops = {
	.owner		= THIS_MODULE,
	.open		= proc_open,
	.read 		= seq_read,
};

static int proc_entry_read(char *buf, char **start, off_t offset, 
                          int len, int *unused_i, void *unused_v)
{
	static const char port_name[]="123456789ABCDEFGH";
	
	return snprintf(buf,strlen(port_name)+1,"%s\n",port_name);
}

static int
proc_entry_write(struct file *file, const char __user * buffer,
		   unsigned 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/ αβ剪枝函数 int alpha_beta(int depth, int alpha, int beta, int color) { if (depth == 0) { return evaluate(currBotColor); // 到达叶节点,返回估值 } int best_score = INT_MIN; vector<pair<int, int> > next_moves = generate_next_moves(); for (auto& next_move : next_moves) { int x = next_move.first; int y = next_move.second; gridInfo[x][y] = color; // 模拟落子 int score = -alpha_beta(depth - 1, -beta, -alpha, -color); // 递归搜索 gridInfo[x][y] = 0; // 撤销落子 if (score > best_score) { best_score = score; if (best_score > alpha) { alpha = best_score; } if (best_score >= beta) { break; // β剪枝 } } } return best_score; } int main() { int x0, y0, x1, y1; // 分析自己收到的输入和自己过往的输出,并恢复棋盘状态 int turnID; cin >> turnID; currBotColor = grid_white; // 先假设自己是白方 for (int i = 0; i < turnID; i++) { // 根据这些输入输出逐渐恢复状态到当前回合 cin >> x0 >> y0 >> x1 >> y1; if (x0 == -1) currBotColor = grid_black; // 第一回合收到坐标是-1, -1,说明我是黑方 if (x0 >= 0) ProcStep(x0, y0, x1, y1, -currBotColor, false); // 模拟对方落子 if (i < turnID - 1) { cin >> x0 >> y0 >> x1 >> y1; if (x0 >= 0) ProcStep(x0, y0, x1, y1, currBotColor, false); // 模拟己方落子 } } /************************************************************************************/ /***在下面填充你的代码,决策结果(本方将落子的位置)存入startX、startY、resultX、resultY中*****/ //下面仅为随机策略的示例代码,且效率低,可删除 int X1, Y1, X2, Y2; bool selfFirstBlack = (turnID == 1 && currBotColor == grid_black);//本方是黑方先手 if(selfFirstBlack){ X1=8; Y1=8; X2=-1; Y2=-1; } else{ } // 决策结束,向平台输出决策结果 cout << X1 << ' ' << Y1 << ' ' << X2 << ' ' << Y2 << endl; return 0; }完善主函数实现六子棋下棋
06-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值