NO.51631のにCPUの強気弱気のモードを加えて
前進しやすい時後退しやすい時があるようにしてみた
randomize
Player_px=100.0
Player_py=400.0
Cpu_px=600.0
Cpu_py=400.0
//CPUモード 0=通常 1=強気 2=弱気
CPU_Mpde=0
CPU_Mpde_txt="通常","強気","弱気"
*main
redraw 0
color 0,50,50
boxf
if rnd(100)=0 {//CPUモード選択(1%の確率でモード選択)
CPU_Mpde=rnd(3)
}else{
if Player_Action="前進" and (rnd(100)<70) {//プレイヤーが前進してたら7割弱気指定
CPU_Mpde=2
}
if Player_Action="後退" and (rnd(100)<30) {//プレイヤーが後退してたら3割通常か強気選択
CPU_Mpde=rnd(2)
}
}
if CPU_Mpde=0 {//モードによる前進確率振り分け
forward=1.0
}else{
if CPU_Mpde=1 {
forward=1.5//前進の確立を1.5倍
}else{
forward=0.2 //前進の確率を0.2倍
}
}
stick stk,255
dx=Player_px-Cpu_px //プレイヤーとCPUの距離
Player_Action=""
if dx<0{//プレイヤーがCPUの左にいる
RL=-1//プレイヤーの左右どっちにいるか
if stk&1 {
Player_Action="後退"
Player_px-0.8
}
if stk&4 {
Player_Action="前進"
Player_px+1.0
}
}else{
RL=1
if stk&1 {
Player_Action="前進"
Player_px-1.0
}
if stk&4 {
Player_Action="後退"
Player_px+0.8
}
}
if stk&16 {//スペース押してる間プレイヤーが攻撃したと設定
Player_Action="攻撃"
}
if Motion_Wait=0 {
if abs(dx)>100 {//距離が100以上
if Action_Time=0{//行動終了
if rnd(100)<(forward*70) {//指定値未満なので前進
CPU_Action="前進"
Action_Time=rnd(30)//30フレーム未満をランダム指定(このフレームの間同じ行動を取る、但し攻撃するかされたら0になる)
}else{
if rnd(100)<90 {//後退指定値未満なので後退
CPU_Action="後退"
Action_Time=rnd(20)
}else{//後退指定値以上なので停止
CPU_Action="停止"
Action_Time=rnd(10)
}
}
}else{
Action_Time--
}
}else{
if Player_Action="攻撃" {//プレイヤーが攻撃中
Action_Time=0
if rnd(100)<(forward*5) {
CPU_Action="前進"
}else{
if rnd(100)<80 {
if rnd(100)<50 {
CPU_Action="後退"
}else{
CPU_Action="防御"
}
}else{
if rnd(100)<30 {
CPU_Action="停止"
}else{
CPU_Action="攻撃"
}
}
}
}else{
if rnd(100)<90 {
if Action_Time=0{
if rnd(100)<(forward*20) {
CPU_Action="前進"
Action_Time=rnd(15)
}else{
if rnd(100)<80 {
CPU_Action="後退"
Action_Time=rnd(5)
}else{
CPU_Action="停止"
Action_Time=rnd(5)
}
}
}else{
Action_Time--
}
}else{
Action_Time=0
CPU_Action="攻撃"
}
}
}
switch CPU_Action
case "停止"
swbreak
case "前進"
if dx<0{
Cpu_px-1.0
}else{
Cpu_px+1.0
}
swbreak
case "後退"
if dx>0{
Cpu_px-0.8
}else{
Cpu_px+0.8
}
swbreak
case "攻撃"
color 200
boxf Cpu_px+50*RL,Cpu_py-32,Cpu_px,Cpu_py
Motion_Wait=10//攻撃中に他の行動が取れるまでのフレーム数
swbreak
case "防御"
color 50,250
boxf Cpu_px+32*RL,Cpu_py-32,Cpu_px,Cpu_py+32
Motion_Wait=5
swbreak
default
swend
}else{//攻撃か防御中
switch CPU_Action
case "攻撃"
color 200
boxf Cpu_px+50*RL,Cpu_py-32,Cpu_px,Cpu_py
swbreak
case "防御"
color 50,250
boxf Cpu_px+32*RL,Cpu_py-32,Cpu_px,Cpu_py+32
swbreak
swend
Motion_Wait--
}
Cpu_px=limitf(Cpu_px,16,624)
color 2255
boxf Cpu_px-16,Cpu_py-32,Cpu_px+16,Cpu_py+32
line Cpu_px+100*RL,Cpu_py+32,Cpu_px,Cpu_py+32
pos Cpu_px-16,Cpu_py-80
mes CPU_Mpde_txt(CPU_Mpde)+"\n"+CPU_Action
color 0,255,255
boxf Player_px-16,Player_py-32,Player_px+16,Player_py+32
pos Player_px-16,Player_py-64
mes Player_Action
redraw 1
await 16
goto *main
ちょっと、ややこしそうに見えるけど
単に確率で行動を振り分けてるだけ