从起点出发找到所有的宝箱之后再寻路到终点
本篇文章禁止转载
图示
寻路需求这次我们在一个多路径迷宫中放置几个宝箱,从起点出发找到所有的宝箱之后再寻路到终点。
演示代码123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 ...
go使用rejson读取redis的json
模块github地址 : https://github.com/nitishm/go-rejson
json
代码123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384package mainimport ( "encoding/json" "fmt" "log" goredis "github.com/go-redis/redis" "github.com/gomodule/redigo/redis" "github.com/nitishm/go-rejson")func main() { // Redigo Client "github.com/gomodule/redigo/red ...
多通路迷宫最短路径
本篇文章禁止转载
Sample algorithm介绍算法适用于有多条路径的迷宫寻找最短路径。
Sample algorithm参考我之前的博客:
迷宫寻路算法(Sample algorithm)
图示
代码演示123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 ...
多通路迷宫生成
本篇文章禁止转载
思路介绍
在已有的单路径迷宫基础上打开一块合适的墙就可以构成2路径的迷宫。
打开的墙不能和已有的路径过近。
1。从开始和终点开始进行广度优先搜索,并为迷宫中的每个单元格记录单元格远离开始和终点的步数。
2。通过将距离开头较近的所有单元格放入 start 集合,并将更接近目标的所有单元格放入end集合来将迷宫分成两个部分。
3。 选择分开两个区域的任意一面墙拆开就可以形成2通路的迷宫。
如想生成最短的通路可以选择相邻格子距离差值最大的那面墙拆开,一般情况下这两条路距离也比较远。分区图分区域演示代码1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151 ...
Sample algorithm算法
本篇文章禁止转载
Sample algorithm算法介绍英文介绍
This is a fairly simple and easy-to-understand pathfinding algorithm for tile-based maps. To start off, you have a map, a start coordinate and a destination coordinate. The map will look like this, X being walls, S being the start, O being the finish and _ being open spaces, the numbers along the top and right edges are the column and row numbers:
First, create a list of coordinates, which we will use as a queue. The queue will be initialized with one coordinat ...
CentOS6 源失效换源
CentOS6 源失效换源
使用root用户操作
删除/etc/yum.repos.d/下所有的.repo。新建立CentOS-Base.repo,内容如下:12345[base]name=CentOS-6failovermethod=prioritybaseurl=https://vault.centos.org/6.9/os/x86_64/gpgcheck=0执行yum clean all清理缓存
执行yum makecache创建缓存
python使用rejson+redis存储json
python安装rejson1pip3 install rejson
Python代码12345678910111213141516171819202122#!/bin/python3# -*- coding=utf-8 -*-import rejson# 连接redisrj = rejson.Client(host='localhost', port=6379, decode_responses=True)def run(): obj={} obj['a']="1" obj['b']="2" # 写入。返回值a为True时写成功 a = rj.jsonset('obj', '.', obj) # 读取。b非None时读取到内容 b = rj.jsonget('obj', '.') print(b) return if ...
ubuntu下配置redis存储json
系统环境Ubuntu 20.04.2 LTS
安装redis1sudo apt install redis
redis安装rejson模块下载rejson模块github地址:https://github.com/RedisJSON/RedisJSON/releases下载Source code(tar.gz) ,可以使用网页直接下载或者使用wget1wget https://github.com/RedisJSON/RedisJSON/archive/refs/tags/v1.0.7.tar.gz
解压1tar xf RedisJSON-1.0.7.tar.gz
编译rejson进入RedisJSON-1.0.7目录,执行make编译完成后会在./src下生成rejson.so
配置rejson复制rejson.so到/usr/lib/1sudo cp ./src/rejson.so /usr/lib/编辑/etc/redis/redis.conf1sudo vim /etc/redis/redis.conf增加loadmodule /usr/lib/rejson.so
重启red ...
深度优先搜索
本篇文章禁止转载
(深度优先搜索)算法介绍介绍1。访问起点;2。依次从起点的未被访问的邻点出发,对迷宫进行深度优先遍历;直至迷宫中起点有路径相通的格子被访问或者找到终点;
编程思路
1。访问起点,起点加入路径表。
2。找可到达且未访问的相邻点。
如果有:
1。移动到相邻的点
2。设置相邻点为当前点
3。当前点加入路径
4。判断是否为终点,否继续循环。
没有:
1。从路径列表中删除当前点
2。设置当前点为路径列表中的最后一个点
图示
演示代码12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712 ...
c++ ustar格式读写
.hflame_ustar.h123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. *//* * File: ...