I made this system for fun, Maybe someone here will find a use for it.
The goal was to make it seem as if the AI was learning but not coded character specific. It records how quickly the AI was defeated in each round and adjusts its "random condition" by averaging the last 2 recorded rounds. If the round is won, to keep the "random condition from dropping, instead of recording the time it was defeated in, it records the average of the last 2 known rounds for that round.
This is my actual work file so there are tons of notes attached. If anyone thinks of improvement, Id' love to hear them.
There is a DisplayToClipboard too so you can keep an eye on whats happening. IntPersistIndex will need to be set to save vars from previous rounds, see notes below.
;==========================================================================
;Inktrebuchet
;Learning AI 3/22/2017
;==========================================================================
;==========================================================================
;Goal:
;-Make AI that appears to learn.
;
;==========================================================================
;Achievements:
;-AI knows how quickly it was defeated in previous round and Adjusts it's "random condition" as needed.
;
;==========================================================================
;notes:
;-set IntPersistIndex = 43 in constants part of the cns
;-assumes timelimit is set to 99. This won't break (reduce probability) if it's not but it won't be as effective.
;-Round 1 has AI set to average. (AIlevel ** 2 / 64.0)*400)
;-borrowed ((root,AIlevel ** 2 / 64.0)*400) from Just No Point / XGargoyle. Used in base example of trigger use below.
;-empty anim = 33333333 was added to air file for helper.
;-if AI wins a round the last two recorded rounds are averaged together to make that rounds "random condition".
;
;
;base example of trigger use: n = normal "random condition" without AI Defeat System.
;trigger1 = random < ((n + ((var(44) + var(45)) / 2)) * (AIlevel ** 2 / 64.0)) ;with AIlevel
;trigger1 = random < (n + ((var(44) + var(45)) / 2))
;--------------------------------------------------------------------------
;==========================================================================
; AI Defeat System Initialization
;==========================================================================
; root Variable usage:
; This is a record of the variables that are used
;
; var(44) - used to record AI's "random condition" after round
; var(45) - used to record AI's "random condition" after round
;--------------------------------------------------------------------------
[Statedef -2]
[state -2, AI Defeat System Helper]
type = helper
trigger1 = ailevel && !numhelper(33333333)
name = "AI Defeat System Helper"
ID = 33333333
stateno = 33333333
postype = p1
ownpal = 1
keyctrl = 0
size.xscale = 1.0
size.yscale = 1.0
supermovetime = 2147483647
pausemovetime = 2147483647
ignorehitpause = 1
[state -1, clip board]
type = DisplayToClipboard
trigger1 = 1
text = " var(44)=%d var(45)= %d last two ave = %d AIlevel limit = %d"
params = var(44), var(45), (var(44) + var(45)) / 2, ((0+((var(44) + var(45)) / 2))*(AIlevel ** 2 / 64.0))
;==========================================================================
; AI Defeat System Helper
;==========================================================================
; numhelper(33333333) Variable usage:
; This is a record of the variables that are used
;
; var(0) - used to manipulate AI formula. [state 33333333, AIlevel formula]
; var(4) - used to record average of last to matches if round is won by AI. [state 33333333, Adjusts "random" *win]
; var(5) - used to record amount of time ai was defeated in each round. [state 33333333, time keeper]
;--------------------------------------------------------------------------
[Statedef 33333333]
type = A
movetype = I
physics = N
ctrl = 0
anim = 33333333
velset = 0, 0
[state 33333333, AIlevel formula] ; used to manipulate AI formula.
type = Varset
triggerall = root, ailevel
trigger1 = 1
v = 0
value = 100 ; This should probably be a formula...
persistent = 0
ignorehitpause = 1
[state 33333333, time keeper] ;tracks how many seconds AI was defeated in.
type = VarAdd
triggerall = root, ailevel
trigger1 = Gametime% 61 = 0 && roundstate > 1 && roundstate < 4 ;speed of timer Gametime%(faster < slower) , 60 = seconds
v = 5
value = 1
ignorehitpause = 1
;--------------------------------------keep var in two slots start----------------------------------------
[state 33333333, Adjusts "random" *lose] ;Used to record AI's "random condition" after round. Condition added to prevents ai from dropping if round is long.
type = parentvarset
triggerall = root, ailevel
trigger1 = root, lose && Gametime% 60 = 0
v = 45
value = cond(cond(roundno = 1,(var(0)*4) - (var(5)*10), cond(((var(0)*4) - (var(5)*10)) >= var(4), (var(0)*4) - (var(5)*10), var(4)))>0,cond(roundno = 1,(var(0)*4) - (var(5)*10), cond(((var(0)*4) - (var(5)*10)) >= var(4), (var(0)*4) - (var(5)*10), var(4))),0) ;simplified version of formula below. has much better range of variables recorded. The below formula kept results between 4 different numbers. also can no longer go below 0!
;value = cond(roundno = 1, cond(var(5)<15,var(0),0) + cond(var(5)<40,var(0),0) + cond(var(5)<65,var(0),0) + cond(var(5)<90,var(0),0), cond((cond(var(5)<15,var(0),0) + cond(var(5)<40,var(0),0) + cond(var(5)<65,var(0),0) + cond(var(5)<90,var(0),0)) >= var(4), cond(var(5)<15,var(0),0) + cond(var(5)<40,var(0),0) + cond(var(5)<65,var(0),0) + cond(var(5)<90,var(0),0), var(4)))
persistent = 0
ignorehitpause = 1
[state 33333333, Adjusts "random" *win] ;Used to record average of last two matches if round is won by AI.
type = varset
triggerall = root, ailevel
trigger1 = 1 ;set to 1 because it's also used in [state 33333333, Adjusts "random" *lose]
v = 4
value = (root, var(44) + root, var(45)) / 2 ;keeps AI level the same if round is won.
persistent = 0
ignorehitpause = 1
[state 33333333, move var(45) to var(44)] ;Designed to save vars. Keep vars down to two.
type = parentvarset
triggerall = root, ailevel
trigger1 = root, lose
trigger2 = root, win && Gametime% 60 = 0
v = 44
value = root, var(45)
persistent = 0
ignorehitpause = 1
[state 33333333, ] ;Designed to save vars. Keep vars down to two.
type = parentvarset
triggerall = root, ailevel
trigger1 = root, win && root, var(44)=root,var(45)
v = 45
value = var(4)
persistent = 0
ignorehitpause = 1
;--------------------------------------keep var in two slots end----------------------------------------
[State 0, BindToRoot]
type = BindToRoot
trigger1 =1
time = 1
facing = 1
pos =0,-5
ignorehitpause =1
persistent =1
And my "random condition" test. *Not that anyone will be needing it.
;==========================================================================
; Guard Master tests
;==========================================================================
[statedef -1]
;test ai "guard everything"
[State -1, test]
type = ChangeState
value = 120
triggerall = ailevel
triggerall= stateno != [120,155]
triggerall = roundstate = 2
triggerall = roundno > 1 && random < (0+((var(44) + var(45)) / 2))
trigger1 = enemy, movetype = A && P2BodyDist X < 20 && Facing = 1 && enemy, Facing = -1
trigger2 = enemy, movetype = A && P2BodyDist X < 20 && Facing = -1 && enemy, Facing = 1
trigger3 = InGuardDist = 1 && random < ((0+((var(44) + var(45)) / 2)) / 5)
;test ai "guard everything" (crouching)
[State -1, test2]
type = ChangeState
value = 10
triggerall = ailevel
triggerall= stateno !=10
triggerall = stateno = 0
triggerall = roundno > 1 && random < (0+((var(44) + var(45)) / 2))
trigger1 = enemy,statetype = c && enemy, movetype = A && P2BodyDist X < 20 && Facing = 1 && enemy, Facing = -1
trigger2 = enemy,statetype = c && enemy, movetype = A && P2BodyDist X < 20 && Facing = -1 && enemy, Facing = 1
trigger3 = InGuardDist = 1 && random < ((0+((var(44) + var(45)) / 2)) / 5)
;--------------------------------------------------------------------------
Updated the first post with this edited state. Just updated the "value" to a formula that records more values. *Still within the same range as the last one.
[state 33333333, Adjusts "random" *lose] ;Used to record AI's "random condition" after round. Condition added to prevents ai from dropping if round is long.
type = parentvarset
triggerall = root, ailevel
trigger1 = root, lose && Gametime% 60 = 0
v = 45
value = cond(roundno = 1,(var(0)*4) - (var(5)*10), cond(((var(0)*4) - (var(5)*10)) >= var(4), (var(0)*4) - (var(5)*10), var(4))) ;simplified version of formula below. has much better range of variables recoded. The below formula kept results between 4 different numbers.
;value = cond(roundno = 1, cond(var(5)<15,var(0),0) + cond(var(5)<40,var(0),0) + cond(var(5)<65,var(0),0) + cond(var(5)<90,var(0),0), cond((cond(var(5)<15,var(0),0) + cond(var(5)<40,var(0),0) + cond(var(5)<65,var(0),0) + cond(var(5)<90,var(0),0)) >= var(4), cond(var(5)<15,var(0),0) + cond(var(5)<40,var(0),0) + cond(var(5)<65,var(0),0) + cond(var(5)<90,var(0),0), var(4)))
persistent = 0
ignorehitpause = 1