Goal Oriented Action Planning
The MIT License (MIT)
Copyright (c) 2014 Nikolay Kush
Goal Oriented Action Planning
License: MIT License
If we follow the example from here;- https://github.com/stolk/GPGOAP
There are 4 steps which should be generated, but plugging in the initial state and goal state from that example page doesn't work in this GOAP project.
I found an alternative;- simply run a check on all the possible combinations/permutations of actions.
using System;
using System.Linq;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
using GOAP;
using GOAP.Planning;
namespace game1
{
public partial class Game1
{
GOAP_1 test = new GOAP_1();
public class GOAP_1
{
public GOAP_1()
{
var planningActions = new List<PlanningAction<State>>
{
new PlanningAction<State>(
name:"load",
validator: x => x["armedWithGun"] == 1,
executor: x =>
{
x["weaponLoaded"] = 1;
}),
new PlanningAction<State>(
name:"detonateBomb",
validator: x => x["armedWithBomb"] == 1 && x["nearEnemy"] == 1,
executor: x =>
{
x["alive"] = 0;
x["enemyAlive"] = 0;
}),
new PlanningAction<State>(
name:"shoot",
validator: x => x["enemyLinedUp"] == 1,
executor: x =>
{
x["enemyAlive"] = 0;
}),
new PlanningAction<State>(
name:"aim",
validator: x => x["enemyVisible"] == 1 && x["weaponLoaded"] == 1,
executor: x =>
{
x["enemyLinedUp"] = 1;
}),
new PlanningAction<State>(
name:"approach",
validator: x => x["enemyVisible"] == 1,
executor: x =>
{
x["nearEnemy"] = 1;
}),
new PlanningAction<State>(
name: "scout",
validator: x => x["armedWithGun"] == 1,
executor: x =>
{
x["enemyVisible"] = 1;
}),
new PlanningAction<State>(
name:"flee",
validator: x => x["enemyVisible"] == 1,
executor: x =>
{
x["nearEnemy"] = 0;
}),
};
initialState = new State
{
{"armedWithGun" , 1},
{"enemyVisible" , 0},
{"nearEnemy" , 0},
{"weaponLoaded" , 0},
{"enemyLinedUp" , 0},
{"enemyAlive" , 1},
{"armedWithBomb" , 1},
{"alive" , 1},
};
goalState = new State
{
{"enemyAlive" , 0},
{"alive" , 1},
};
var steps = makePlan(initialState, goalState, planningActions);
foreach(var step in steps) //plan
{
//..
}
}
static List<PlanningAction<State>> makePlan(State initialState, State goalState, List<PlanningAction<State>> actions)
{
foreach(var action in actions)
{
var qualified = action.validator((State)initialState.Clone());
if(!qualified) continue;
var state1 = action.Execute((State)initialState.Clone());
foreach(var action2 in actions)
{
if(action2 != action)
{
var qualified2 = action2.validator(state1);
if(!qualified2) continue;
var state2 = action2.Execute(state1);
foreach(var action3 in actions)
{
if(action3 != action && action3 != action2)
{
var qualified3 = action3.validator(state2);
if(!qualified3) continue;
var state3 = action3.Execute(state2);
foreach(var action4 in actions)
{
if(action4 != action && action4 != action2 && action4 != action3)
{
var qualified4 = action4.validator(state3);
if(!qualified4) continue;
var state4 = action4.Execute(state3);
foreach(var action5 in actions)
{
if(action5 != action && action5 != action2 && action5 != action3 && action5 != action4)
{
var qualified5 = action5.validator(state4);
if(!qualified5) continue;
var state5 = action5.Execute(state4);
}
}
if(goalStateSatisfied(state4, goalState)) return makeSteps(action, action2, action3, action4);
}
}
if(goalStateSatisfied(state3, goalState)) return makeSteps(action, action2, action3);
}
}
if(goalStateSatisfied(state2, goalState)) return makeSteps(action, action2);
}
}
if(goalStateSatisfied(state1, goalState)) return makeSteps(action);
}
return new List<PlanningAction<State>>();
}
static bool goalStateSatisfied(State currState, State goalState)
{
foreach(var kvp in goalState)
{
if(kvp.Value == currState[kvp.Key])
continue;
return false;
}
return true;
}
static List<PlanningAction<State>> makeSteps(params PlanningAction<State>[] actions)
{
List<PlanningAction<State>> steps = new List<PlanningAction<State>>();
foreach(var action in actions)
steps.Add(action);
return steps;
}
static State initialState;
static State goalState;
}
}
}
Is it possible to add some information about how the projects works?
Can you attach a license file for this repository? Or can we reference the code freely?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.