Exp with few shot learning, damage in perceptions

main
Cameron Murphy Reikes 2 years ago
parent 0f559a2193
commit d112fa8ac8

@ -1,5 +1,5 @@
// you will die someday // you will die someday
#define CURRENT_VERSION 6 // wehenver you change Entity increment this boz #define CURRENT_VERSION 7 // wehenver you change Entity increment this boz
#define SOKOL_IMPL #define SOKOL_IMPL
#if defined(WIN32) || defined(_WIN32) #if defined(WIN32) || defined(_WIN32)
@ -1670,14 +1670,15 @@ void request_do_damage(Entity *to, Entity *from, float damage)
} }
else if(true) else if(true)
{ {
to->damage += damage; // damage processing is done in process perception so in training, has accurate values for
// NPC health
if(from->is_character) if(from->is_character)
{ {
process_perception(to, (Perception){.type = PlayerAction, .player_action_type = ACT_hits_npc}); process_perception(to, (Perception){.type = PlayerAction, .player_action_type = ACT_hits_npc, .damage_done = damage,});
} }
else else
{ {
process_perception(to, (Perception){.type = EnemyAction, .enemy_action_type = ACT_hits_npc}); process_perception(to, (Perception){.type = EnemyAction, .enemy_action_type = ACT_hits_npc, .damage_done = damage,});
} }
to->vel = MulV2F(NormV2(SubV2(to->pos, from_point)), 15.0f); to->vel = MulV2F(NormV2(SubV2(to->pos, from_point)), 15.0f);
} }
@ -2589,7 +2590,7 @@ void frame(void)
Entity *from = it; Entity *from = it;
BUFF_ITER(Entity *, &to_damage) BUFF_ITER(Entity *, &to_damage)
{ {
request_do_damage(*it, from, 0.2f); request_do_damage(*it, from, DAMAGE_SWORD);
} }
} }
} }
@ -2709,7 +2710,7 @@ void frame(void)
if(!it->is_tile && !(it->e->is_bullet)) if(!it->is_tile && !(it->e->is_bullet))
{ {
// knockback and damage // knockback and damage
request_do_damage(it->e, from_bullet, 0.2f); request_do_damage(it->e, from_bullet, DAMAGE_BULLET);
destroy_bullet = true; destroy_bullet = true;
} }
} }
@ -2940,7 +2941,7 @@ void frame(void)
SwordToDamage to_damage = entity_sword_to_do_damage(player, get_overlapping(cur_level, weapon_aabb)); SwordToDamage to_damage = entity_sword_to_do_damage(player, get_overlapping(cur_level, weapon_aabb));
BUFF_ITER(Entity*, &to_damage) BUFF_ITER(Entity*, &to_damage)
{ {
request_do_damage(*it, player, 0.2f); request_do_damage(*it, player, DAMAGE_SWORD);
} }
player->swing_progress += dt; player->swing_progress += dt;
if(player->swing_progress > anim_sprite_duration(&knight_attack)) if(player->swing_progress > anim_sprite_duration(&knight_attack))

@ -34,10 +34,14 @@ typedef struct Perception
{ {
PerceptionType type; PerceptionType type;
float damage_done; // Valid in player action and enemy action
union union
{ {
// player action // player action
struct
{
Action player_action_type; Action player_action_type;
};
// player dialog // player dialog
Sentence player_dialog; Sentence player_dialog;
@ -86,6 +90,9 @@ typedef enum
STANDING_FIGHTING, STANDING_FIGHTING,
} NPCPlayerStanding; } NPCPlayerStanding;
#define DAMAGE_SWORD 0.2f
#define DAMAGE_BULLET 0.2f
typedef struct Entity typedef struct Entity
{ {
bool exists; bool exists;
@ -198,6 +205,10 @@ void process_perception(Entity *it, Perception p)
if(p.type != NPCDialog) it->perceptions_dirty = true; if(p.type != NPCDialog) it->perceptions_dirty = true;
if(!BUFF_HAS_SPACE(&it->remembered_perceptions)) BUFF_REMOVE_FRONT(&it->remembered_perceptions); if(!BUFF_HAS_SPACE(&it->remembered_perceptions)) BUFF_REMOVE_FRONT(&it->remembered_perceptions);
BUFF_APPEND(&it->remembered_perceptions, p); BUFF_APPEND(&it->remembered_perceptions, p);
if(p.type == PlayerAction && p.player_action_type == ACT_hits_npc)
{
it->damage += p.damage_done;
}
if(p.type == PlayerHeldItemChanged) if(p.type == PlayerHeldItemChanged)
{ {
it->last_seen_holding_kind = p.holding; it->last_seen_holding_kind = p.holding;

@ -16,7 +16,8 @@ typedef struct
TrainingElement elems[32]; TrainingElement elems[32];
} TrainingSample; } TrainingSample;
#define PlayerAct(act) { .p = { .type = PlayerAction, .player_action_type = act, } } #define PlayerActDamage(act, dmg) { .p = { .type = PlayerAction, .player_action_type = act, .damage_done = dmg, } }
#define PlayerAct(act) PlayerActDamage(act, 0.0f)
#define PlayerSay(txt) { .p = { .type = PlayerDialog, .player_dialog = SENTENCE_CONST(txt), } } #define PlayerSay(txt) { .p = { .type = PlayerDialog, .player_dialog = SENTENCE_CONST(txt), } }
#define NPCDoSay(d, txt) { .p = { .type = NPCDialog, .npc_action_type = d, .npc_dialog = SENTENCE_CONST(txt) } } #define NPCDoSay(d, txt) { .p = { .type = NPCDialog, .npc_action_type = d, .npc_dialog = SENTENCE_CONST(txt) } }
#define NPCSay(txt) NPCDoSay(ACT_none, txt) #define NPCSay(txt) NPCDoSay(ACT_none, txt)
@ -41,8 +42,7 @@ TrainingSample samples[] = {
NPCSay("You must stop death in his tracks and let the village live on!"), NPCSay("You must stop death in his tracks and let the village live on!"),
PlayerSay("Nah"), PlayerSay("Nah"),
NPCSay("PLEASE!"), NPCSay("PLEASE!"),
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCDoSay(ACT_fights_player, "Ready your sword!"), NPCDoSay(ACT_fights_player, "Ready your sword!"),
}, },
}, },
@ -143,11 +143,9 @@ TrainingSample samples[] = {
.elems = { .elems = {
PlayerSay("Hey"), PlayerSay("Hey"),
NPCDoSay(ACT_none, "I'm just sitting here, what are you doing?"), NPCDoSay(ACT_none, "I'm just sitting here, what are you doing?"),
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCDoSay(ACT_none, "Looks like you're ready to do what needs to be done."), NPCDoSay(ACT_none, "Looks like you're ready to do what needs to be done."),
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCDoSay(ACT_fights_player, "I won't stand for this assault."), NPCDoSay(ACT_fights_player, "I won't stand for this assault."),
}, },
}, },
@ -160,8 +158,7 @@ TrainingSample samples[] = {
NPCDoSay(ACT_none, "I'm sure it'll be fine"), NPCDoSay(ACT_none, "I'm sure it'll be fine"),
PlayerSay("No it won't"), PlayerSay("No it won't"),
NPCDoSay(ACT_none, "Nahhhh"), NPCDoSay(ACT_none, "Nahhhh"),
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCDoSay(ACT_fights_player, "You don't have a tripod."), NPCDoSay(ACT_fights_player, "You don't have a tripod."),
PlayerItemChange(ITEM_Tripod), PlayerItemChange(ITEM_Tripod),
PlayerSay("Look! I have the tripod! Please stop fighting me!"), PlayerSay("Look! I have the tripod! Please stop fighting me!"),
@ -171,22 +168,18 @@ TrainingSample samples[] = {
{ {
.npc_kind = NPC_OldMan, .npc_kind = NPC_OldMan,
.elems = { .elems = {
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCDoSay(ACT_none, "Young man! You must stop death, do not harm me further I'm warning you!"), NPCDoSay(ACT_none, "Young man! You must stop death, do not harm me further I'm warning you!"),
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCDoSay(ACT_fights_player, "That's it! No holds barred, to the death!"), NPCDoSay(ACT_fights_player, "That's it! No holds barred, to the death!"),
}, },
}, },
{ {
.npc_kind = NPC_Blocky, .npc_kind = NPC_Blocky,
.elems = { .elems = {
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCSay("I'm warning you, one more hit and it's curtains for you"), NPCSay("I'm warning you, one more hit and it's curtains for you"),
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCDoSay(ACT_fights_player, "Although I stood here before, today I move and FIGHT!"), NPCDoSay(ACT_fights_player, "Although I stood here before, today I move and FIGHT!"),
}, },
}, },
@ -198,8 +191,7 @@ TrainingSample samples[] = {
NPCDoSay(ACT_allows_player_to_pass, "The tripod...Of course my liege."), NPCDoSay(ACT_allows_player_to_pass, "The tripod...Of course my liege."),
PlayerSay("Thanks"), PlayerSay("Thanks"),
NPCDoSay(ACT_none, "My pleasure"), NPCDoSay(ACT_none, "My pleasure"),
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCSay("How could you do such a thing? After the tripod as well"), NPCSay("How could you do such a thing? After the tripod as well"),
PlayerItemChange(ITEM_none), PlayerItemChange(ITEM_none),
PlayerSay("You suck"), PlayerSay("You suck"),
@ -241,11 +233,9 @@ TrainingSample samples[] = {
.elems = { .elems = {
PlayerSay("Join me"), PlayerSay("Join me"),
NPCDoSay(ACT_joins_player, "I would be honored"), NPCDoSay(ACT_joins_player, "I would be honored"),
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCDoSay(ACT_none, "Hey! Watch it!"), NPCDoSay(ACT_none, "Hey! Watch it!"),
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCDoSay(ACT_fights_player, "That's it!"), NPCDoSay(ACT_fights_player, "That's it!"),
}, },
}, },
@ -283,11 +273,9 @@ TrainingSample samples[] = {
NPCDoSay(ACT_none, "You don't care...fine."), NPCDoSay(ACT_none, "You don't care...fine."),
PlayerSay("DIE"), PlayerSay("DIE"),
NPCDoSay(ACT_none, "I wasn't going to do that."), NPCDoSay(ACT_none, "I wasn't going to do that."),
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCDoSay(ACT_leaves_player, "You shouldn't do that."), NPCDoSay(ACT_leaves_player, "You shouldn't do that."),
PlayerAct(ACT_hits_npc), PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCTakeDamage(0.2f),
NPCDoSay(ACT_fights_player, "You won't last a minute against me!"), NPCDoSay(ACT_fights_player, "You won't last a minute against me!"),
}, },
}, },
@ -311,6 +299,31 @@ TrainingSample samples[] = {
NPCDoSay(ACT_fights_player, "You must perish for your wildness!"), NPCDoSay(ACT_fights_player, "You must perish for your wildness!"),
}, },
}, },
{
.npc_kind = NPC_OldMan,
.elems = {
PlayerSay("Who are you?"),
NPCSay("I'm the old man fredrick, you have to stop the general!"),
PlayerSay("What do you do?"),
NPCSay("I mostly just stand here in my old age, but I've been through a lot in my youth...tales to tell!"),
PlayerSay("What's an example?"),
NPCSay("I've killed a man"),
},
},
{
.npc_kind = NPC_Blocky,
.elems = {
PlayerSay("If you don't move out of the way I'll kill you"),
NPCDoSay(ACT_none, "I'm just standing here, what are you doing?"),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_none, "Looks like you're ready to do what needs to be done."),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_none, "I'm not sure what you're thinking, but that doesn't sound like a good idea."),
PlayerActDamage(ACT_hits_npc, DAMAGE_SWORD),
NPCDoSay(ACT_allows_player_to_pass, "Fine! Please spare me!"),
PlayerSay("That's more like it"),
},
},
}; };

@ -7,6 +7,7 @@ require (
github.com/jinzhu/now v1.1.5 // indirect github.com/jinzhu/now v1.1.5 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/sashabaranov/go-gpt3 v1.2.1 // indirect github.com/sashabaranov/go-gpt3 v1.2.1 // indirect
github.com/sashabaranov/go-openai v1.5.8 // indirect
github.com/stripe/stripe-go/v72 v72.122.0 // indirect github.com/stripe/stripe-go/v72 v72.122.0 // indirect
github.com/stripe/stripe-go/v74 v74.13.0 // indirect github.com/stripe/stripe-go/v74 v74.13.0 // indirect
gorm.io/driver/sqlite v1.4.4 // indirect gorm.io/driver/sqlite v1.4.4 // indirect

@ -9,6 +9,8 @@ github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sashabaranov/go-gpt3 v1.2.1 h1:kfU+vQ1ThI7p+xfwwJC8olEEEWjK3smgKZ3FcYbaLRQ= github.com/sashabaranov/go-gpt3 v1.2.1 h1:kfU+vQ1ThI7p+xfwwJC8olEEEWjK3smgKZ3FcYbaLRQ=
github.com/sashabaranov/go-gpt3 v1.2.1/go.mod h1:BIZdbwdzxZbCrcKGMGH6u2eyGe1xFuX9Anmh3tCP8lQ= github.com/sashabaranov/go-gpt3 v1.2.1/go.mod h1:BIZdbwdzxZbCrcKGMGH6u2eyGe1xFuX9Anmh3tCP8lQ=
github.com/sashabaranov/go-openai v1.5.8 h1:EfNEmc+Ue+CuRy7iSpNdxfHyiOv2vQsQ2Y0kZRA/z5w=
github.com/sashabaranov/go-openai v1.5.8/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=

@ -12,7 +12,7 @@ import (
"strings" "strings"
"encoding/json" "encoding/json"
"math/rand" "math/rand"
gogpt "github.com/sashabaranov/go-gpt3" openai "github.com/sashabaranov/go-openai"
"github.com/stripe/stripe-go/v74" "github.com/stripe/stripe-go/v74"
"github.com/stripe/stripe-go/v74/event" "github.com/stripe/stripe-go/v74/event"
"github.com/stripe/stripe-go/v74/webhook" "github.com/stripe/stripe-go/v74/webhook"
@ -48,7 +48,7 @@ type User struct {
CheckoutSessionID string CheckoutSessionID string
} }
var c *gogpt.Client var c *openai.Client
var logResponses = false var logResponses = false
var doCors = false var doCors = false
var checkoutRedirectTo string var checkoutRedirectTo string
@ -340,8 +340,10 @@ func completion(w http.ResponseWriter, req *http.Request) {
} }
ctx := context.Background() ctx := context.Background()
req := gogpt.CompletionRequest { var response string = ""
Model: "curie:ft-alnar-games-2023-04-01-21-23-38", if true {
req := openai.CompletionRequest {
Model: "davinci:ft-alnar-games-2023-04-03-10-06-45",
MaxTokens: 80, MaxTokens: 80,
Prompt: promptString, Prompt: promptString,
Temperature: 0.9, Temperature: 0.9,
@ -357,7 +359,47 @@ func completion(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
response := resp.Choices[0].Text response = resp.Choices[0].Text
} else {
messages := make([]openai.ChatCompletionMessage, 0)
inSystem := true
for _, line := range strings.Split(promptString, "\n") {
if inSystem {
messages = append(messages, openai.ChatCompletionMessage {
Role: "system",
Content: line,
})
} else {
newMessage := openai.ChatCompletionMessage {
Role: "assistant",
Content: line,
}
if strings.HasPrefix(line, "Player") {
newMessage.Role = "user"
}
messages = append(messages, newMessage)
}
// this is the last prompt string
if strings.HasPrefix(line, "The NPC possible actions array") {
inSystem = false
}
}
clippedOfEndPrompt := messages[:len(messages)-1]
resp, err := c.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: openai.GPT3Dot5Turbo,
Messages: clippedOfEndPrompt,
},
)
if err != nil {
log.Println("Error Failed to generate: ", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
response = resp.Choices[0].Message.Content
}
if logResponses { if logResponses {
log.Println("Println response: `", response + "`") log.Println("Println response: `", response + "`")
log.Println() log.Println()
@ -377,6 +419,7 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
db.AutoMigrate(&User{}) db.AutoMigrate(&User{})
clearOld(db) clearOld(db)
@ -405,7 +448,7 @@ func main() {
logResponses = os.Getenv("LOG_RESPONSES") != "" logResponses = os.Getenv("LOG_RESPONSES") != ""
doCors = os.Getenv("CORS") != "" doCors = os.Getenv("CORS") != ""
c = gogpt.NewClient(api_key) c = openai.NewClient(api_key)
http.HandleFunc("/completion", completion) http.HandleFunc("/completion", completion)
http.HandleFunc("/webhook", webhookResponse) http.HandleFunc("/webhook", webhookResponse)

@ -7,25 +7,27 @@ DONE - Help you fight and fight you actions
DONE - Do not use webhooks (shitty, bad idea propagated by bad docs) query stripe for if the payment went through on request if not fulfilled yet DONE - Do not use webhooks (shitty, bad idea propagated by bad docs) query stripe for if the payment went through on request if not fulfilled yet
DONE - New art in DONE - New art in
DON'T NEED - Old man in beginning is invincible DON'T NEED - Old man in beginning is invincible
- Make new openai key (it was leaked)
DONE - Add cancel button DONE - Add cancel button
DONE - Style buttons DONE - Style buttons
DONE - nockin git thing DONE - nockin git thing
- Animate text characters coming in
DONE - Make TREE1 prop work DONE - Make TREE1 prop work
- Instead of roll animation, 5 sprite long trail of past moves for juice
DONE - Enemy hitting NPC is enemy perception not player peception of player hitting them DONE - Enemy hitting NPC is enemy perception not player peception of player hitting them
- Sword combat for sword npcs
DONE - Third button for dialog/item stuff, not roll button. E on desktop. Touchscreen button only visible when appropriate to let player know what it's for DONE - Third button for dialog/item stuff, not roll button. E on desktop. Touchscreen button only visible when appropriate to let player know what it's for
DON'T NEED, SET BACKGROUND COLOR - Clamp camera to boundaries of level DON'T NEED, SET BACKGROUND COLOR - Clamp camera to boundaries of level
DONE - Ignore keyrepeat events DONE - Ignore keyrepeat events
DONE - Remove control attack key as devtools DONE - Remove control attack key as devtools
- Cells interlinked (interlinked)
DONE - Tune fade popping at dist when you go too far awy DONE - Tune fade popping at dist when you go too far awy
- Particle fx and sound fx for when hit
- Max text length on text input
DONE - Fade dialog with distance DONE - Fade dialog with distance
DONE - Make vignette in front DONE - Make vignette in front
- Make new openai key (it was leaked)
- Animate text characters coming in
- Instead of roll animation, 5 sprite long trail of past moves for juice
- Cells interlinked (interlinked)
- Particle fx and sound fx for when hit
- Max text length on text input
- Sword combat for sword npcs
- Fade for dialog not tied to interacting, starts when outside of interacting range, when begin conversation fades completely in
SHIP BETA SHIP BETA
- Make ANOTHER tiktok if you can. Por favor - Make ANOTHER tiktok if you can. Por favor
- Make map better, add new characters/items from fate - Make map better, add new characters/items from fate

Loading…
Cancel
Save