Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TESTING
- #define DEBUG
- #define SAVE_DEBUG_TREE
- using System;
- using System.Linq;
- using System.IO;
- using System.Text;
- using System.Collections;
- using System.Diagnostics;
- using System.Collections.Generic;
- public class Game
- {
- public enum ActionTypes { BREW, CAST, OPCAST, LEARN, NONE };
- public static void DebugPrint(string txt)
- {
- #if DEBUG && TESTING
- Console.Error.WriteLine(txt);
- #endif
- }
- public class DebugTree
- {
- public static string StrTree
- {
- get
- {
- #if DEBUG && TESTING
- return mTree.ToString();
- #endif
- return "";
- }
- }
- //echo "graph TST{a0 -- {a1 a2} ; a1 -- {a3 a4} ; a2 -- {a5 a6} ;}" | dot -Tpng > out.png
- //graph TST{a0 -- { a1 b1}; a1 [label="a1=-2147483648 Beta",color=blue]; b1 [label="b1=-2147483648 Beta",color=blue]; a0 [label="a0=2147483647"];a1 -- { a2 b2}; a2 [label="a2=2147483647 Alpha",color=red]; b2 [label="b2=2147483647 Alpha",color=red];}
- public static void Init()
- {
- #if DEBUG && TESTING
- mTree = new StringBuilder();
- mChildsList = new SortedList<int, List<(State, State)>>();
- // mTree.Append("graph TST{");
- mChildNum = 0;
- #endif
- }
- public static void BeginChilds()
- {
- #if DEBUG && TESTING
- #endif
- }
- public static void EndChilds()
- {
- #if DEBUG && TESTING
- #endif
- }
- public static void SetChilds(int depth, State par, State ch)
- {
- #if DEBUG && TESTING
- if (!mChildsList.ContainsKey(depth))
- {
- mChildsList.Add(depth, new List<(State, State)>());
- }
- mChildsList[depth].Add((par, ch));
- mChildNum++;
- #endif
- }
- public static void SetEnd()
- {
- #if DEBUG && TESTING
- // mTree.Append(" }");
- var i = -1;
- foreach (var item in mChildsList)
- {
- mTree.Append($"\r\n- \t{item.Key}\t -\r\n");
- foreach (var item1 in item.Value)
- {
- mTree.Append($"depth: {item.Key} parent: {item1.Item1.PlayerData} - evalby: {item1.Item1.EvalActID} , child: {item1.Item2.PlayerData} - evalby: {item1.Item2.EvalActID} - evaval: {item1.Item2.EvalVal}; ");
- }
- }
- #if SAVE_DEBUG_TREE
- File.WriteAllText("tmptree01.txt", mTree.ToString());
- #endif
- #endif
- }
- private static (string, string) mParent;
- private static SortedList<int, List<(State, State)>> mChildsList;
- private static StringBuilder mTree;
- private static int mChildNum;
- }
- public struct Action
- {
- public Action(string ln)
- {
- var inputs = ln.Split(' ');
- // $"{ActionId} {ActionId} {Deltas[0]} {Deltas[1]} {Deltas[2]} {Deltas[3]} {Price} {TomeIndex} {TaxCount} {Castable} {Repeatable} "
- ActionId = int.Parse(inputs[0]); // the unique ID of this spell or recipe
- StrActionType = inputs[1].Trim(); // in the first league: BREW; later: CAST, OPPONENT_CAST, LEARN, BREW
- Deltas = new int[4];
- Deltas[0] = int.Parse(inputs[2]); // tier-0 ingredient change
- Deltas[1] = int.Parse(inputs[3]); // tier-1 ingredient change
- Deltas[2] = int.Parse(inputs[4]); // tier-2 ingredient change
- Deltas[3] = int.Parse(inputs[5]); // tier-3 ingredient change
- Price = int.Parse(inputs[6]); // the price in rupees if this is a potion
- TomeIndex = int.Parse(inputs[7]); // in the first two leagues: always 0; later: the index in the tome if this is a tome spell, equal to the read-ahead tax
- TaxCount = int.Parse(inputs[8]); // in the first two leagues: always 0; later: the amount of taxed tier-0 ingredients you gain from learning this spell
- Castable = inputs[9] != "0"; // in the first league: always 0; later: 1 if this is a castable player spell
- Repeatable = inputs[10] != "0"; // for the first two leagues: always 0; later: 1 if this is a repeatable player spell
- Type = ActionTypes.NONE;
- if (StrActionType.Equals("BREW"))
- {
- Type = ActionTypes.BREW;
- }
- else if (StrActionType.Equals("CAST"))
- {
- Type = ActionTypes.CAST;
- }
- else if (StrActionType.Equals("LEARN"))
- {
- Type = ActionTypes.LEARN;
- }
- else if (StrActionType.Equals("OPPONENT_CAST"))
- {
- Type = ActionTypes.OPCAST;
- }
- }
- public override string ToString()
- {
- return $"{ActionId} {ActionId} {Deltas[0]} {Deltas[1]} {Deltas[2]} {Deltas[3]} {Price} {TomeIndex} {TaxCount} {Castable} {Repeatable} ";
- }
- public ActionTypes Type; //
- public int ActionId; // the unique ID of this spell or recipe
- public string StrActionType; // in the first league: BREW; later: CAST, OPPONENT_CAST, LEARN, BREW
- public int[] Deltas; //indigriedns deltas
- public int Price; // the price in rupees if this is a potion
- public int TomeIndex; // in the first two leagues: always 0; later: the index in the tome if this is a tome spell, equal to the read-ahead tax
- public int TaxCount; // in the first two leagues: always 0; later: the amount of taxed tier-0 ingredients you gain from learning this spell
- public bool Castable; // in the first league: always 0; later: 1 if this is a castable player spell
- public bool Repeatable; // for the first two leagues: always 0; later: 1 if this is a repeatable player spell
- }
- public struct PData
- {
- public PData(string ln)
- {
- var inputs = ln.Split(' ');
- //
- Inventories = new int[4];
- Inventories[0] = int.Parse(inputs[0]); // tier-0 ingredients in inventory
- Inventories[1] = int.Parse(inputs[1]);
- Inventories[2] = int.Parse(inputs[2]);
- Inventories[3] = int.Parse(inputs[3]);
- Scores = int.Parse(inputs[4]); // amount of rupees
- }
- public PData(PData pdata)
- {
- Inventories = new int[4];
- pdata.Inventories.CopyTo(Inventories, 0);
- Scores = pdata.Scores;
- }
- public override string ToString()
- {
- return $"{Inventories[0]} {Inventories[1]} {Inventories[2]} {Inventories[3]} {Scores} ";
- }
- public int[] Inventories; //inventories
- public int Scores;// amount of rupees
- }
- public class State
- {
- public int EvalActID => mEvalActID;
- public int OptimalFirstMove => mOptimalFirstMove;
- public State Parent => mParent;
- public List<State> Childrens => mChildrens;
- public double EvalVal => mEvalVal;
- public List<Action> Actions => mActions;
- public PData PlayerData => mPlayerData;
- public PData OppData => mOpponentData;
- public List<Action> BrewActs => mBrewActs;
- public List<Action> CastsActs => mCastsActs;
- public List<Action> UnCastsActs => mUnCastsActs;
- public List<Action> OpCastsActs => mOpCastsActs;
- public List<Action> CanLearn => mCanLearn;
- //brew diffs
- public Dictionary<int, int[]> BDiffs => mBDiffs;
- //casts diffs
- public Dictionary<int, int[]> CDiffs => mCDiffs;
- //uncastable diffs
- public Dictionary<int, int[]> UnCDiffs => mUnCDiffs;
- //brew if can with max
- public Dictionary<int, int[]> BrewCansDiffd => mBrewCansDiffd;
- //cast
- public Dictionary<int, int[]> CastCansDiffd => mCastCansDiffd;
- //uncastable can do
- public Dictionary<int, int[]> UnCastCansDiffd => mUnCastCansDiffd;
- public List<Action> CastsCans => mCastsCans;
- public List<Action> UnCastsCans => mUnCastsCans;
- //same as new inventory after spell cast
- public Dictionary<int, int[]> CastsCansDiffDiff => mCastsCansDiffDiff;
- //same as new inventory after spell uncast
- public Dictionary<int, int[]> UnCastsCansDiffDiff => mUnCastsCansDiffDiff;
- //rest if brew next move
- //Can do brew next move check
- public List<int> UnCastDiff3 => mUnCastDiff3;
- //Can do brew next move check
- public List<int> CastDiff3 => mCastDiff3;
- //FirstBrewMoves was called
- public bool FirstBrIsEval => mFirstBrIsEval;
- public State(List<Action> actions, PData playerData, PData opponentData, int actionCount, State parent = null, int evActID = -1)
- {
- mActionCount = actionCount;
- mActions = actions;
- mPlayerData = playerData;
- mOpponentData = opponentData;
- mEvalVal = 0;
- mParent = parent;
- mChildrens = new List<State>();
- mEvalActID = evActID;
- mFirstBrIsEval = false;
- UpdateActsVals();
- }
- public void AddChilderen(State children)
- {
- mChildrens.Add(children);
- }
- public void UpdateActsVals()
- {
- mBrewActs = Actions.Where(act => act.Type == ActionTypes.BREW)?.ToList();
- mCastsActs = Actions.Where(act => act.Type == ActionTypes.CAST && act.Castable)?.ToList();
- mUnCastsActs = Actions.Where(act => act.Type == ActionTypes.CAST && !act.Castable)?.ToList();
- mOpCastsActs = Actions.Where(act => act.Type == ActionTypes.OPCAST)?.ToList();
- mLearnActs = mActions.Where(act => act.Type == ActionTypes.LEARN)?.ToList();
- ///
- //brew diffs
- mBDiffs = GetInvDiffs(mBrewActs);
- //casts diffs
- mCDiffs = GetInvDiffs(mCastsActs);
- //uncastable diffs
- mUnCDiffs = GetInvDiffs(mUnCastsActs);
- //brew if can with max
- mBrewCansDiffd = CanDo(mBDiffs);
- ///
- //cast
- mCastCansDiffd = CanDo(mCDiffs);
- //uncastable can do
- mUnCastCansDiffd = CanDo(mUnCDiffs);
- ///
- //
- mCastsCans = mCastsActs.Where(v => (v.Deltas.Sum() + mPlayerData.Inventories.Sum()) < 11
- && mCastCansDiffd.Any(ba => ba.Key == v.ActionId))?.ToList();
- //
- mUnCastsCans = mUnCastsActs.Where(v => (v.Deltas.Sum() + mPlayerData.Inventories.Sum()) < 11
- && mUnCastCansDiffd.Any(ba => ba.Key == v.ActionId))?.ToList();
- ///
- //TODO: optim . remove need only one check in CanDo
- //same as new inventory after spell cast
- mCastsCansDiffDiff = GetInvDiffs(CastsCans);
- //same as new inventory after spell uncast
- mUnCastsCansDiffDiff = GetInvDiffs(mUnCastsCans);
- //rest if brew next move
- //Can do brew next move check
- mUnCastDiff3 = GetCastDiffsBrewNext(mBrewActs, mUnCastsCansDiffDiff);
- //Can do brew next move check
- mCastDiff3 = GetCastDiffsBrewNext(mBrewActs, CastsCansDiffDiff);
- //total inv
- mCurrentTotalInv = mPlayerData.Inventories.Sum();
- //
- mCanLearn = mLearnActs.Where(ll => ll.TomeIndex <= mPlayerData.Inventories[0]).ToList();
- }
- public State EvaluateByActId(int actId)
- {
- List<Action> actions = new List<Action>();
- actions.AddRange(mActions);
- PData playerData = new PData(mPlayerData);
- PData opponentData = new PData(mOpponentData);
- int actionCount = mActionCount;
- //Evaluate actions
- if (actId == -1)
- {
- var castbls = Actions.Where(act => act.Type == ActionTypes.CAST && !act.Castable)?.ToList();
- foreach (var castbl in castbls)
- {
- int actind = actions.FindIndex(aa => aa.ActionId == castbl.ActionId);
- var act = actions[actind];
- act.Castable = true;
- actions[actind] = act;
- }
- }
- else
- {
- int actind = actions.FindIndex(aa => aa.ActionId == actId);
- var act = actions[actind];
- switch (act.Type)
- {
- case ActionTypes.CAST:
- act.Castable = false;
- for (int i = 0; i < 4; i++)
- {
- playerData.Inventories[i] = mCastsCansDiffDiff[actId][i];
- }
- actions[actind] = act;
- break;
- case ActionTypes.LEARN:
- playerData.Inventories[0] += act.TaxCount - act.TomeIndex;
- act.Castable = true;
- act.StrActionType = "CAST";
- act.Type = ActionTypes.CAST;
- actions.Add(act);
- actions.RemoveAt(actind);
- break;
- case ActionTypes.BREW:
- actions.RemoveAt(actind);
- break;
- }
- }
- State nstate = new State(actions, playerData, opponentData, actionCount, this, actId);
- mChildrens.Add(nstate);
- return nstate;
- }
- //first best moves eval
- //-1 -- not found
- public int FirstBrewMoves()
- {
- mFirstBrIsEval = true;
- //TODO: never happens
- if (mBrewCansDiffd.Count > 0)
- {
- var brewmax = GetMaxPriceArr(mBrewCansDiffd, mBrewActs);
- var brrand = brewmax[(new Random(DateTime.Now.Millisecond)).Next(0, brewmax.Length)];
- mEvalVal = brrand.Price * 5;
- mOptimalFirstMove = brrand.ActionId;
- return mOptimalFirstMove;
- }
- //[a,b] , b - negative from bdiffs a
- int[,] Wishes = GetWishesFromBDiffs(mBDiffs);
- if (mCastCansDiffd.Count > 0)
- {
- //rest if UnCastsCans can brew next move
- if (mUnCastsCans != null && mUnCastsCans.Count > 0)
- {
- if (mUnCastDiff3 != null && mUnCastDiff3.Count > 0)
- {
- // DebugPrint("!!!!!!!!!!!!!!REST for brew next move !!!!!!!!!!");
- mEvalVal = 5;
- return -1;
- }
- }
- //casts
- if (mCastsCans != null)
- {
- double TotalPositiveInv = (mPlayerData.Inventories.Where(v => v > 0)?.Sum(vv => 10 / (double)vv)) ?? 0;
- double SoLargeInv = (mPlayerData.Inventories.Where(v => v > 1)?.Sum()) ?? 0;
- var TotalPositiveCastsDiff = (mCastsCansDiffDiff.Select((vv, TPosVal) => new
- {
- Key = vv.Key,
- Val = vv,
- Sum = vv.Value.Sum(),
- SoLarge = vv.Value.Where(vv0 => vv0 > 1)?.Sum() ?? 0,
- TotalPos = (double)(vv.Value.Where(vv0 => 10 / (double)vv0 > 0)?.Sum() ?? 0)
- }));
- //Can do brew next move check
- if (mCastDiff3 != null && mCastDiff3.Count > 0)
- {
- mEvalVal = 5;
- mOptimalFirstMove = mCastDiff3.First();
- return mOptimalFirstMove;
- }
- //rest if couldn't get 1/3
- // //uncommon remove?
- double rest_ratio = (double)mCastsActs.Count() / (double)mUnCastsActs.Count();
- if (mCastsActs.Count > 9 && rest_ratio < 0.2)
- {
- mEvalVal = 0;
- //DebugPrint("!!!!!!!!!! rest 0.3 !!!!!!!!!!!!!!!!!");
- return -1;
- }
- //Can
- //learn if not enought spells
- //learn test //2
- if (mCastsCans.Count < 2)
- {
- mOptimalFirstMove = Learn(Wishes);
- if (mOptimalFirstMove > -1)
- {
- mEvalVal = 0;//1
- return mOptimalFirstMove;
- }
- }
- //eval cast
- double evaval = Double.MinValue;
- int retcast_actid = -1;
- //int uplim=casts.Count==4?11:10 ;
- int uplim = 9;
- foreach (var castactt in TotalPositiveCastsDiff)
- {
- double cevaval = (castactt.TotalPos - TotalPositiveInv) + (SoLargeInv - castactt.SoLarge) * 3;
- if (cevaval > evaval && castactt.Sum < uplim && !LastSpellWasRemoved(castactt.Val.Value))
- {
- evaval = cevaval;
- retcast_actid = castactt.Key;
- }
- }
- if (retcast_actid > -1)
- {
- mEvalVal = 0;
- mOptimalFirstMove = retcast_actid;
- return mOptimalFirstMove;
- }
- else if ((mCastsCans.Count < 3 && rest_ratio < 1.5) || (rest_ratio > 3 && mCurrentTotalInv >= 10))
- {
- mOptimalFirstMove = Learn(Wishes);
- if (mOptimalFirstMove > -1)
- {
- mEvalVal = 0;
- return mOptimalFirstMove;
- }
- }
- }
- // return (castCansDiffd.ElementAt((new Random(DateTime.Now.Millisecond)).Next(0, castCansDiffd.Count - 1)).Key);
- }
- //rest
- mOptimalFirstMove = -1;
- mEvalVal = 0;
- return -1;
- }
- // diffs beetween inventory and action list
- private Dictionary<int, int[]> GetInvDiffs(List<Action> acts)
- {
- return GetDiffs(acts, mPlayerData.Inventories);
- }
- // cast_id - new inv[]
- // dicVals -- new invetories dic
- //used for check if can brew next move
- private List<int> GetCastDiffsBrewNext(List<Action> acts, Dictionary<int, int[]> dicVals)
- {
- List<int> diffs = new List<int>();
- foreach (var pair in dicVals)
- {
- var tmp = GetDiffs(acts, pair.Value);
- var tmp_can = CanDo(tmp);
- if (tmp_can != null && tmp_can.Count > 0) diffs.Add(pair.Key);
- }
- return diffs;
- }
- //diff between actions and arr
- private Dictionary<int, int[]> GetDiffs(List<Action> acts, int[] vals)
- {
- Dictionary<int, int[]> diffs = new Dictionary<int, int[]>(); // mPlayerData.Inv +
- foreach (var act in acts)
- {
- var diff = new int[4];
- for (int i = 0; i < act.Deltas.Length; i++)
- {
- int ad = act.Deltas[i];
- diff[i] = vals[i] + ad;
- }
- diffs.Add(act.ActionId, diff);
- }
- return diffs;
- }
- //vals wish casts
- public int Learn(int[,] vals)
- {
- int ret = -1;
- // List<Action> learn_acts = mActions.Where(act => act.StrActionType.Equals("LEARN"))?.ToList();
- if (mLearnActs != null && mLearnActs.Count > 0)
- {
- if (mCanLearn != null && mCanLearn.Count() > 0 && vals != null)
- {
- var can_learn_diffs = GetInvDiffs(mCanLearn);
- var can_learn_can_do = CanDo(can_learn_diffs);
- int max = Int32.MinValue;
- int act_id = -1;
- foreach (var can_lact in can_learn_can_do)
- {
- for (int i = 0; i < vals.GetLength(0); i++)
- {
- int sum = 0;
- for (int j = 0; j < vals.GetLength(1); j++)
- {///???????
- var wval = vals[i, j]; //if 0 didn't calc, we didn't need it//give worth results
- // if (wval < 0)
- {
- var lactv = can_lact.Value[j];
- sum += (wval + lactv); // 0< lim -> 0
- }
- }
- if (sum > max)
- {
- max = sum;
- act_id = can_lact.Key;
- }
- }
- }
- if (act_id > -1) return act_id;
- }
- if (mCanLearn != null && mCanLearn.Count() > 0)
- return (mCanLearn[(new Random(DateTime.Now.Millisecond)).Next(0, mCanLearn.Count())].ActionId);
- }
- return ret;
- }
- // wishes negative values what we need
- public int[,] GetWishesFromBDiffs(Dictionary<int, int[]> bdiffs)
- {
- int[,] wishes = new int[bdiffs.Count, 4];
- for (int i = 0; i < bdiffs.Count; i++)
- {
- if (bdiffs.ElementAt(i).Value.Any(v => v < 0))
- {
- for (int j = 0; j < 4; j++)
- {
- int val = bdiffs.ElementAt(i).Value[j];
- if (val < 0)
- wishes[i, j] = val;
- else
- wishes[i, j] = 0;
- }
- }
- }
- return wishes;
- }
- public bool LastSpellWasRemoved(int[] checvals)
- {
- for (int i = 0; i < checvals.Length; i++)
- {
- if (checvals[i] == 0 && mPlayerData.Inventories[i] != 0)
- {
- return true;
- }
- }
- return false;
- }
- public Action[] GetMaxPriceArr(Dictionary<int, int[]> candiffs, List<Action> acts)
- {
- var ActsCans = acts.Where(v => candiffs.Any(ba => ba.Key == v.ActionId)).ToList(); // brewCansDiffd.Where( v => bacts.Any(ad => ad.ActionId==v.Key)) ;
- int maxprice = ActsCans.Max(m => m.Price);
- var brewmax = ActsCans.Where(v => v.Price == maxprice).ToArray();
- return brewmax;
- }
- //brew dic - breew diff inv+brew
- private Dictionary<int, int[]> CanDo(Dictionary<int, int[]> dic)
- {
- Dictionary<int, int[]> cans = new Dictionary<int, int[]>();
- foreach (var d in dic)
- {
- if (d.Value.Any(v => v < 0)) continue;
- cans.Add(d.Key, d.Value);
- }
- return cans;
- }
- private int mOptimalFirstMove = -1;
- private bool mFirstBrIsEval;
- private int mCurrentTotalInv;
- private double mEvalVal;
- private List<Action> mActions;
- private int mActionCount;
- private PData mPlayerData;
- private PData mOpponentData;
- private int mEvalActID; // was evaluated by this action
- private State mParent;
- private List<State> mChildrens;
- private List<Action> mBrewActs;
- private List<Action> mCastsActs;
- private List<Action> mUnCastsActs;
- private List<Action> mOpCastsActs;
- private List<Action> mLearnActs;
- //
- private List<Action> mCanLearn;
- //brew diffs
- private Dictionary<int, int[]> mBDiffs;
- //casts diffs
- private Dictionary<int, int[]> mCDiffs;
- //uncastable diffs
- private Dictionary<int, int[]> mUnCDiffs;
- //brew if can with max
- private Dictionary<int, int[]> mBrewCansDiffd;
- //
- //cast
- private Dictionary<int, int[]> mCastCansDiffd;
- //uncastable can do
- private Dictionary<int, int[]> mUnCastCansDiffd;
- //
- private List<Action> mCastsCans;
- private List<Action> mUnCastsCans;
- //
- //same as new inventory after spell cast
- private Dictionary<int, int[]> mCastsCansDiffDiff;
- //same as new inventory after spell uncast
- private Dictionary<int, int[]> mUnCastsCansDiffDiff;
- //rest if brew next move
- //Can do brew next move check
- private List<int> mUnCastDiff3;
- //Can do brew next move check
- private List<int> mCastDiff3;
- //
- }
- public class Evalator
- {
- public Evalator(int actCount, List<Action> actions, PData playerDat, PData oppDat)
- {
- mStates = new Stack<State>();
- mStates.Push(new State(actions, playerDat, oppDat, actCount));
- }
- public string Evaluate()
- {
- //1. get all possible acts exclude Brew
- //2. walk over
- //3. evaluate them
- //4. FirstBrewMoves (add calc return to) for every
- //5. generate tree walk over
- // in the first league: BREW <id> | WAIT; later: BREW <id> | CAST <id> [<times>] | LEARN <id> | REST | WAIT
- try
- {
- var curst = mStates.Peek();
- DebugTree.Init();
- //DebugTree.SetParent($"{curst.PlayerData}");
- Process(curst, 0);
- DebugTree.SetEnd();
- var stree = DebugTree.StrTree;
- var retv = RecalAct(curst, 0);
- int actid = -1;
- //DebugPrint($"!!!! {retv.Item2} !!!!! {retv.Item1} !!!!");
- if (retv.Item1 > 60 && retv.Item2 > -1)
- {
- DebugPrint($"!!!! {retv.Item2} !!!!! {retv.Item1} !!!!");
- actid = retv.Item2;
- }
- else
- {
- actid = curst.OptimalFirstMove;
- }
- if (actid > -1)
- {
- var act = mStates.Peek().Actions.First(av => av.ActionId == actid);
- return $"{act.StrActionType} {act.ActionId}";
- }
- }
- catch (Exception e)
- {
- DebugPrint($"Exception!!!!!!!!!! msg: {e.Message}\r\n stack trace: {e.StackTrace} \r\n ");
- }
- return "REST";
- }
- //ret max, EvalActId
- private (double, int) RecalAct(State st, int depth)
- {
- if (depth > mMaxDepth)
- {
- return (0, -1);
- }
- double max = double.MinValue;
- int eactid = -1;
- foreach (var cst in st.Childrens)
- {
- double c = cst.EvalVal;
- var tmp = RecalAct(cst, ++depth);
- c += tmp.Item1;
- if (c > max)
- {
- max = c;
- eactid = cst.EvalActID;
- }
- }
- return (max, eactid);
- }
- private void Process(State st, int depth)
- {
- if (depth > mMaxDepth)
- {
- return;
- }
- var fmactId = st.FirstBrewMoves();
- foreach (var canacts in st.CastsCans)
- {
- var nst = st.EvaluateByActId(canacts.ActionId);
- Process(nst, 1 + depth);
- }
- #if DEBUG && TESTING
- foreach (var nst in st.Childrens)
- {
- DebugTree.SetChilds(depth, st, nst);
- }
- #endif
- }
- private int mMaxDepth = 10;
- private Stack<State> mStates;
- }
- public static string ExecuteCommand(string command, string args)
- {
- Process proc = new System.Diagnostics.Process();
- string out_txt = "";
- proc.StartInfo.FileName = $"{command}";
- proc.StartInfo.Arguments = $" {args}";
- proc.StartInfo.UseShellExecute = false;
- proc.StartInfo.RedirectStandardOutput = true;
- proc.Start();
- StreamReader reader = proc.StandardOutput;
- out_txt = reader.ReadToEnd();
- return out_txt;
- }
- public static void Start()
- {
- // game loop
- while (true)
- {
- int actionCount = int.Parse(Console.ReadLine()); // the number of spells and recipes in play
- DebugPrint($"actionCount: {actionCount}");
- List<Action> Actions = new List<Action>();
- for (int i = 0; i < actionCount; i++)
- {
- var ln0 = Console.ReadLine();
- DebugPrint($"actions 0: {ln0}");
- Actions.Add(new Action(ln0));
- }
- //
- var ln1 = Console.ReadLine();
- DebugPrint($"player data : {ln1}");
- PData pdat = new PData(ln1);
- ln1 = Console.ReadLine();
- DebugPrint($"op data : {ln1}");
- PData opdat = new PData(ln1);
- Evalator evl = new Evalator(actionCount, Actions, pdat, opdat);
- // in the first league: BREW <id> | WAIT; later: BREW <id> | CAST <id> [<times>] | LEARN <id> | REST | WAIT
- Console.WriteLine(evl.Evaluate());
- }
- }
- // public static void Main(string[] args) => Start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement