コード例 #1
0
        internal static void CreateDomain(string domainName, string domainXml, IEnumerable <XmlFile> variants)
        {
            NegotiationContainer cont = new NegotiationContainer();

            var domainVariants = variants.Select(x => new DomainVariant()
            {
                Name = x.Name, VariantXML = x.Content
            }).ToList();

            cont.DomainVariantSet.AddRange(domainVariants);

            cont.GameDomainSet.Add(new GameDomain()
            {
                Name          = domainName,
                DomainXML     = domainXml,
                DomainVariant = domainVariants
            });

            cont.SaveChanges();

            if (GameDomain == null)
            {
                SetNewDomain(cont.GameDomainSet.First().Id);
            }
        }
コード例 #2
0
        public static AiConfig GetAiConfig()
        {
            NegotiationContainer cont = new NegotiationContainer();
            var gameConfig            = cont.GameDomainConfigSet.FirstOrDefault();

            if (gameConfig == null)
            {
                return(new AiConfig()
                {
                    Side = "",
                    Variant = "",
                    Type = UserType.Agent,
                    StrategyId = 0
                });
            }

            var strat = cont.StrategyConfigSet.FirstOrDefault();

            return(new AiConfig
            {
                Side = gameConfig.AiSide,
                Variant = gameConfig.AiVariant,
                Type = UserType.Agent,
                StrategyId = strat != null ? strat.Id : 0
            });
        }
コード例 #3
0
        private static void SetupStrategy()
        {
            NegotiationContainer cont = new NegotiationContainer();
            var strat = cont.StrategyConfigSet.FirstOrDefault();

            if (strat != null)
            {
                m_currentStrategyDirPath = Path.GetDirectoryName(HttpContext.Current.Server.MapPath(strat.Strategy.DllPath));
            }
        }
コード例 #4
0
        static void LoadDbData()
        {
            var domainConfig = new NegotiationContainer().GameDomainConfigSet.FirstOrDefault();

            if (domainConfig != null)
            {
                Config     = domainConfig;
                GameDomain = domainConfig.GameDomain;

                LoadDomain();
            }
        }
コード例 #5
0
        internal static void SetDomainVariants(string humanSide, string humanVariant, string aiVariant)
        {
            NegotiationContainer cont = new NegotiationContainer();
            var domainConfig          = cont.GameDomainConfigSet.First();

            domainConfig.HumanSide    = humanSide;
            domainConfig.HumanVariant = humanVariant;
            domainConfig.AiSide       = Domain.OwnerVariantDict.Keys.Except(humanSide).First();
            domainConfig.AiVariant    = aiVariant;

            cont.SaveChanges();

            Config = domainConfig;
        }
コード例 #6
0
        internal static void SaveNegotiationEnd(String negotiationId, int humanScore, int agentScore, DateTime negotiationEndTime)
        {
            NegotiationContainer cont = new NegotiationContainer();
            var game = cont.GameSet.Find(negotiationId);

            if (game == null)
            {
                return;
            }

            game.Users.First(x => x.Type == UserType.Agent).Score = agentScore;
            game.Users.First(x => x.Type == UserType.Human).Score = humanScore;
            game.Endtime = negotiationEndTime;

            cont.SaveChanges();
        }
コード例 #7
0
        internal static IAgentStrategy GetStrategy(int strategyId, out String strategyName)
        {
            NegotiationContainer cont = new NegotiationContainer();
            var strat = cont.StrategySet.Find(strategyId);

            String dllPath = HttpContext.Current.Server.MapPath(strat.DllPath);
            String dllDir  = System.IO.Path.GetDirectoryName(dllPath);

            Assembly assembly = Assembly.LoadFile(dllPath);

            Type           type    = assembly.GetTypes().First(x => x.GetInterface("IAgentStrategy") != null);
            IAgentStrategy example = assembly.CreateInstance(type.FullName) as IAgentStrategy;

            strategyName = strat.StrategyName;

            return(example);
        }
コード例 #8
0
        internal static void CreateStrategy(string strategyName, string DllPath)
        {
            NegotiationContainer cont = new NegotiationContainer();

            cont.StrategySet.Add(new Strategy()
            {
                StrategyName = strategyName,
                DllPath      = DllPath
            });

            cont.SaveChanges();

            if (!cont.StrategyConfigSet.Any())
            {
                SetNewStrategy(cont.StrategySet.First().Id);
            }
        }
コード例 #9
0
        private static void SaveAction(NegotiationEngine engine, SideConfig side, NegotiationActionType type, String value = "")
        {
            NegotiationContainer cont = new NegotiationContainer();

            var game = cont.GameSet.Find(engine.NegotiationId);
            var user = game.Users.First(x => x.Type == side.Type);

            cont.NegotiationActionSet.Add(new NegotiationAction()
            {
                GameId        = engine.NegotiationId,
                Type          = type,
                User          = user,
                RemainingTime = engine.Status.RemainingTime,
                UserId        = user.Id,
                Value         = value
            });
            cont.SaveChanges();
        }
コード例 #10
0
        internal static void SetNewStrategy(int newActiveStrategy)
        {
            NegotiationContainer cont = new NegotiationContainer();

            var stratId = GetAiConfig().StrategyId;

            if (stratId != 0)
            {
                cont.StrategyConfigSet.Remove(cont.StrategyConfigSet.Find(stratId));
            }

            cont.StrategyConfigSet.Add(new StrategyConfig()
            {
                Id = newActiveStrategy
            });
            cont.SaveChanges();

            SetupStrategy();
        }
コード例 #11
0
        internal static void SetNewDomain(int newActiveDomain)
        {
            NegotiationContainer cont = new NegotiationContainer();

            if (GameDomain != null)
            {
                var activeConfig = cont.GameDomainConfigSet.Find(GameDomain.Id);
                if (activeConfig != null)
                {
                    cont.GameDomainConfigSet.Remove(activeConfig);
                }
            }

            GameDomain = cont.GameDomainSet.Find(newActiveDomain);
            LoadDomain();

            string humanSide = Domain.OwnerVariantDict.Keys.First();
            string aiSide    = Domain.OwnerVariantDict.Keys.ElementAt(1);

            Config = new GameDomainConfig()
            {
                Id           = newActiveDomain,
                HumanSide    = humanSide,
                HumanVariant = Domain.OwnerVariantDict[humanSide].Keys.First(),
                AiSide       = aiSide,
                AiVariant    = Domain.OwnerVariantDict[aiSide].Keys.First()
            };

            cont.GameDomainConfigSet.Add(Config);

            try
            {
                cont.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }

            LoadDbData();
        }
コード例 #12
0
        internal static void SaveNegotiationEnd(String negotiationId, int humanScore, int agentScore, DateTime negotiationEndTime)
        {
            NegotiationContainer cont = new NegotiationContainer();
            var game = cont.GameSet.Find(negotiationId);

            if (game == null) return;

            game.Users.First(x => x.Type == UserType.Agent).Score = agentScore;
            game.Users.First(x => x.Type == UserType.Human).Score = humanScore;
            game.Endtime = negotiationEndTime;

            cont.SaveChanges();
        }
コード例 #13
0
 internal static object GetUser(string userId)
 {
     NegotiationContainer cont = new NegotiationContainer();
     return cont.UserSet.Find(userId);
 }
コード例 #14
0
        internal static IAgentStrategy GetStrategy(int strategyId, out String strategyName)
        {
            NegotiationContainer cont = new NegotiationContainer();
            var strat = cont.StrategySet.Find(strategyId);

            String dllPath = HttpContext.Current.Server.MapPath(strat.DllPath);
            String dllDir = System.IO.Path.GetDirectoryName(dllPath);

            Assembly assembly = Assembly.LoadFile(dllPath);

            Type type = assembly.GetTypes().First(x => x.GetInterface("IAgentStrategy") != null);
            IAgentStrategy example = assembly.CreateInstance(type.FullName) as IAgentStrategy;

            strategyName = strat.StrategyName;

            return example;
        }
コード例 #15
0
 internal static IEnumerable<Game> GetGames()
 {
     NegotiationContainer cont = new NegotiationContainer();
     return cont.GameSet;
 }
コード例 #16
0
 internal static object GetGame(string gameId)
 {
     NegotiationContainer cont = new NegotiationContainer();
     return cont.GameSet.Find(gameId);
 }
コード例 #17
0
        internal static IEnumerable <Game> GetGames()
        {
            NegotiationContainer cont = new NegotiationContainer();

            return(cont.GameSet);
        }
コード例 #18
0
        static void LoadDbData()
        {
            var domainConfig = new NegotiationContainer().GameDomainConfigSet.FirstOrDefault();

            if (domainConfig != null)
            {
                Config = domainConfig;
                GameDomain = domainConfig.GameDomain;

                LoadDomain();
            }
        }
コード例 #19
0
        internal static void SetNewDomain(int newActiveDomain)
        {
            NegotiationContainer cont = new NegotiationContainer();

            if (GameDomain != null)
            {
                var activeConfig = cont.GameDomainConfigSet.Find(GameDomain.Id);
                if (activeConfig != null)
                {
                    cont.GameDomainConfigSet.Remove(activeConfig);
                }
            }

            GameDomain = cont.GameDomainSet.Find(newActiveDomain);
            LoadDomain();

            string humanSide = Domain.OwnerVariantDict.Keys.First();
            string aiSide = Domain.OwnerVariantDict.Keys.ElementAt(1);

            Config = new GameDomainConfig()
            {
                Id = newActiveDomain,
                HumanSide = humanSide,
                HumanVariant = Domain.OwnerVariantDict[humanSide].Keys.First(),
                AiSide = aiSide,
                AiVariant = Domain.OwnerVariantDict[aiSide].Keys.First()
            };

            cont.GameDomainConfigSet.Add(Config);

            try
            {
                cont.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }

            LoadDbData();
        }
コード例 #20
0
        internal static void SaveNewNegotiation(NegotiationEngine engine, PreNegotiationQuestionnaireViewModel model)
        {
            NegotiationContainer cont = new NegotiationContainer();

            #region Human User
            UserRole humanRole = new UserRole()
            {
                Description = engine.HumanConfig.Side,
                Variant = engine.HumanConfig.Variant
            };

            UserData humanData = new UserData()
            {
                AgeRange = model.AgeRange,
                Country = model.BirthCountry,
                DegreeField = model.DegreeField,
                Education = model.Education,
                Gender = model.Gender,
                StudentId = model.ID,
                Name = model.Name,
                University = model.University
            };

            User humanUser = new User()
            {
                Id = engine.NegotiationId,
                Type = UserType.Human,
                UserData = humanData,
                UserRole = humanRole,
                GameId = engine.NegotiationId
            };

            #endregion

            #region Ai User

            UserRole aiRole = new UserRole()
            {
                Description = engine.AiConfig.Side,
                Variant = engine.AiConfig.Variant
            };

            User aiUser = new User()
            {
                Id = engine.StrategyName + "|" + DateTime.Now,
                Type = UserType.Agent,
                StrategyId = engine.AiConfig.StrategyId,
                UserRole = aiRole,
                GameId = engine.NegotiationId,
            };

            #endregion

            cont.GameSet.Add(new Game()
                {
                    Id = engine.NegotiationId,
                    GameDomainId = GameDomain.Id,
                    StartTime = DateTime.Now
                });

            cont.UserDataSet.Add(humanData);
            cont.UserRoleSet.Add(humanRole);
            cont.UserRoleSet.Add(aiRole);
            cont.UserSet.Add(humanUser);
            cont.UserSet.Add(aiUser);

            try
            {
                cont.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #21
0
        internal static object GetUser(string userId)
        {
            NegotiationContainer cont = new NegotiationContainer();

            return(cont.UserSet.Find(userId));
        }
コード例 #22
0
        internal static object GetGame(string gameId)
        {
            NegotiationContainer cont = new NegotiationContainer();

            return(cont.GameSet.Find(gameId));
        }
コード例 #23
0
        internal static void SetDomainVariants(string humanSide, string humanVariant, string aiVariant)
        {
            NegotiationContainer cont = new NegotiationContainer();
            var domainConfig = cont.GameDomainConfigSet.First();

            domainConfig.HumanSide = humanSide;
            domainConfig.HumanVariant = humanVariant;
            domainConfig.AiSide = Domain.OwnerVariantDict.Keys.Except(humanSide).First();
            domainConfig.AiVariant = aiVariant;

            cont.SaveChanges();

            Config = domainConfig;
        }
コード例 #24
0
        private static void SetupStrategy()
        {
            NegotiationContainer cont = new NegotiationContainer();
            var strat = cont.StrategyConfigSet.FirstOrDefault();

            m_currentStrategyDirPath = Path.GetDirectoryName(HttpContext.Current.Server.MapPath(strat.Strategy.DllPath));
        }
コード例 #25
0
        internal static void SetNewStrategy(int newActiveStrategy)
        {
            NegotiationContainer cont = new NegotiationContainer();

            var stratId = GetAiConfig().StrategyId;
            if (stratId != 0)
            {
                cont.StrategyConfigSet.Remove(cont.StrategyConfigSet.Find(stratId));
            }

            cont.StrategyConfigSet.Add(new StrategyConfig() { Id = newActiveStrategy });
            cont.SaveChanges();

            SetupStrategy();
        }
コード例 #26
0
        internal static void SaveNewNegotiation(NegotiationEngine engine, PreNegotiationQuestionnaireViewModel model)
        {
            NegotiationContainer cont = new NegotiationContainer();

            #region Human User
            UserRole humanRole = new UserRole()
            {
                Description = engine.HumanConfig.Side,
                Variant     = engine.HumanConfig.Variant
            };

            UserData humanData = new UserData()
            {
                AgeRange    = model.AgeRange,
                Country     = model.BirthCountry,
                DegreeField = model.DegreeField,
                Education   = model.Education,
                Gender      = model.Gender,
                StudentId   = model.ID,
                Name        = model.Name,
                University  = model.University
            };

            User humanUser = new User()
            {
                Id       = engine.NegotiationId,
                Type     = UserType.Human,
                UserData = humanData,
                UserRole = humanRole,
                GameId   = engine.NegotiationId
            };

            #endregion

            #region Ai User

            UserRole aiRole = new UserRole()
            {
                Description = engine.AiConfig.Side,
                Variant     = engine.AiConfig.Variant
            };

            User aiUser = new User()
            {
                Id         = engine.StrategyName + "|" + DateTime.Now,
                Type       = UserType.Agent,
                StrategyId = engine.AiConfig.StrategyId,
                UserRole   = aiRole,
                GameId     = engine.NegotiationId,
            };

            #endregion

            cont.GameSet.Add(new Game()
            {
                Id           = engine.NegotiationId,
                GameDomainId = GameDomain.Id,
                StartTime    = DateTime.Now
            });

            cont.UserDataSet.Add(humanData);
            cont.UserRoleSet.Add(humanRole);
            cont.UserRoleSet.Add(aiRole);
            cont.UserSet.Add(humanUser);
            cont.UserSet.Add(aiUser);

            try
            {
                cont.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #27
0
        private static void SaveAction(NegotiationEngine engine, SideConfig side, NegotiationActionType type, String value = "")
        {
            NegotiationContainer cont = new NegotiationContainer();

            var game = cont.GameSet.Find(engine.NegotiationId);
            var user = game.Users.First(x => x.Type == side.Type);

            cont.NegotiationActionSet.Add(new NegotiationAction()
            {
                GameId = engine.NegotiationId,
                Type = type,
                User = user,
                RemainingTime = engine.Status.RemainingTime,
                UserId = user.Id,
                Value = value
            });
            cont.SaveChanges();
        }
コード例 #28
0
        internal static void CreateStrategy(string strategyName, string DllPath)
        {
            NegotiationContainer cont = new NegotiationContainer();

            cont.StrategySet.Add(new Strategy()
            {
                StrategyName = strategyName,
                DllPath = DllPath
            });

            cont.SaveChanges();

            if (!cont.StrategyConfigSet.Any())
            {
                SetNewStrategy(cont.StrategySet.First().Id);
            }
        }
コード例 #29
0
        public static AiConfig GetAiConfig()
        {
            NegotiationContainer cont = new NegotiationContainer();
            var gameConfig = cont.GameDomainConfigSet.First();
            var strat = cont.StrategyConfigSet.FirstOrDefault();

            return new AiConfig
            {
                Side = gameConfig.AiSide,
                Variant = gameConfig.AiVariant,
                Type = UserType.Agent,
                StrategyId = strat != null ? strat.Id : 0
            };
        }
コード例 #30
0
        internal static void CreateDomain(string domainName, string domainXml, IEnumerable<XmlFile> variants)
        {
            NegotiationContainer cont = new NegotiationContainer();

            var domainVariants = variants.Select(x => new DomainVariant() { Name = x.Name, VariantXML = x.Content }).ToList();
            cont.DomainVariantSet.AddRange(domainVariants);

            cont.GameDomainSet.Add(new GameDomain()
                {
                    Name = domainName,
                    DomainXML = domainXml,
                    DomainVariant = domainVariants
                });

            cont.SaveChanges();

            if (GameDomain == null)
            {
                SetNewDomain(cont.GameDomainSet.First().Id);
            }
        }