double VPaiNextState(ChessState state, StrategyState strategy) { int Tot = 0; bool isKing = state.State[strategy.SlcR][strategy.SlcC] == ChessType.BKing; string mstate = ChessState.StateToStr(state); string astrategy = StrategyState.StaToStr(strategy); //插入决策 DataOperation.InsertStrategy(astrategy); VSTimes[] NsT = new VSTimes[10000]; NsT = DataOperation.SelectProbTimes(mstate, astrategy); //计算V(s+1) double NS = 0.0; for (int i = 0; i < NsT.Count(); i++) { NS += NsT[i].Vs * NsT[i].times; Tot += NsT[i].times; } if (Tot > 0) NS /= Tot; //从数据库里读出v(s) double vs = DataOperation.SelectVState(mstate); //从数据库读出瞬时回报值 double r = DataOperation.SelectReward(mstate, astrategy, isKing); //计算现在的v(s) vs = vs + a * (r + u * NS - vs); return vs; }
public static VSTimes[] SelectProbTimes(string state, string strategy) { int i = 0; VSTimes[] tmps = new VSTimes[10000]; BlackTD0DataContext blackTD0 = new BlackTD0DataContext(); var tmp = from c in blackTD0.STATEs from o in blackTD0.ASTRATEGies from e in blackTD0.PROBs from f in blackTD0.VSTATEs where c.SNO == e.SNO && f.SNO == c.SNO && o.ANO == e.ANO && c.MSTATE == state && o.STRATEGY == strategy select new { f.VALUE, e.TIMES }; if (tmp.Count() > 0) { foreach (var c in tmp) tmps[i++] = new VSTimes(c.VALUE, c.TIMES); } return tmps; }