Example #1
0
        public List <GameFrameModel> DisplayFreeGameFrames()
        {
            var prox = new DBFunctionsClient();

            prox.Open();
            var GameFrames = prox.RetreiveFreeGameFrame().ToList();

            return(GameFrames);
        }
Example #2
0
        public string EditGameFrame(GameFrameModel edited)
        {
            var prox = new DBFunctionsClient();

            prox.Open();
            int result = prox.UpdateGameFrame(edited);

            if (result == 1)
            {
                return("success");
            }
            else
            {
                return("error");
            }
        }
Example #3
0
        public void LogNashPointsinDB(int GID, List <PF> OrderedPlayers, List <NE_Profile> NashPoints) //adds founded nash points to database (npprofile,npstrategy, nppayoff)
        {                                                                                              //underconstruction
            var DBsvc = new DBFunctionsClient();

            foreach (var np in NashPoints)
            {
                //Add npprofile
                //GId , add func from db
                NashPointProfileModel nppoint = new NashPointProfileModel();
                nppoint.GID = GID;
                int NPID = DBsvc.AddNashPointProfile(nppoint);
                //Add npstrategy
                //get -> username , strategy id , NPID
                //wrapper_TwoThree.playerInfo;
                //Add nppayoff nppayoff1 -> player 1 ....
            }
        }
Example #4
0
        public string DeleteGameFrame(string title)
        {
            var cont = new DBFunctionsClient();

            cont.Open();
            List <GameFrameModel> unlinkedGF = new List <GameFrameModel>();

            int result = cont.DeleteGameFrame(title);

            if (result == 1)
            {
                return("sucess");
            }
            else
            {
                return("error");
            }
        }
Example #5
0
        public List <GameFrameModel> ChooseGame(int nop)//returns a list of all possibel GFs with a certain number of players
        {
            List <GameFrameModel> availableGFs = new List <GameFrameModel>();
            var cont = new DBFunctionsClient();

            try
            {
                cont.Open();
                List <GameFrameModel> gfmodels = cont.GameByNumPlayer(nop).ToList();
                cont.Close();
                return(gfmodels);
            }
            catch (ProtocolException ex)
            {
                Console.Write(ex.ToString());
            }
            // this method then displays the gfs to the user
            return(null);
        }
Example #6
0
        public string Register(UserModel us)
        {
            //   var prox = new DBFunctionsClient();
            var pro = new SeniorDBServiceRef.DBFunctionsClient();

            SeniorDBServiceRef.DBFunctionsClient p = new DBFunctionsClient();
            try
            {
                pro.Open();
                pro.AddUser(us);
                pro.Close();
            }
            catch (ProtocolException ex)
            {
                return(ex.ToString());
            }

            return("done!");
        }
Example #7
0
        public PF CheckGameStatus(string desiredgame, string username)//1 if the min num required is reached // -1 if still waiting
        {
            int  GID       = 0;
            var  prox      = new DBFunctionsClient();
            bool isInQueue = wrapper_TwoThree.Player_GameFrame_Queue.ContainsKey(username);

            if (!isInQueue)//if the player is not in the queue , this means that the game is already created
            {
                List <GamePlayerModel> games = prox.RetreiveAllGamePlayersByPlayer(username).ToList();
                GamePlayerModel        gp    = games.ElementAt(games.Count - 1);//last gameplayer
                foreach (PF p in wrapper_TwoThree.playerInfo)
                {
                    if (p.username == username)
                    {
                        return(p);
                    }
                }
                return(null);
            }
            else
            {
                //get the min num required for the games , then check if the nop is sufficient
                List <string> opengames = findKeyforValue(wrapper_TwoThree.Player_GameFrame_Queue, desiredgame);//players in this game

                prox.Open();
                int minplayers = prox.RetreiveMinPlayers(desiredgame);    //get the min nop required in the desired game
                int maxplayers = prox.RetreiveMaxPlayers(desiredgame);    //get the max nop of the game
                //   prox.Close();

                if (opengames.Count < minplayers)//if the required number of players is not reached
                {
                    return(null);
                }
                if (opengames.Count > maxplayers)                                    //if opengames has a number of players that exceeds the max of the game, remove the exceeding players
                {
                    opengames.RemoveRange(maxplayers, opengames.Count - maxplayers); //remove players from index max until reaching (opengames.Count - maxplayers)-count
                }
                if (opengames.Count >= minplayers && opengames.Count <= maxplayers)  //if the opengames count equals the number of players required for the game then add a new game and return the ID
                {
                    GameModel newGame = new GameModel();
                    newGame.NPlayers = minplayers;
                    newGame.Title    = desiredgame;
                    GID = prox.AddGame(newGame);//add the new game
                    List <List <string> > strategies     = new List <List <string> >();
                    List <string>         tempstrategies = new List <string>();
                    int counterfororderofplayers         = 0;
                    for (int i = 0; i < opengames.Count; i++)// search the queue to add the players
                    {
                        GamePlayerModel player = new GamePlayerModel();
                        PF ppp = new PF();
                        player.UserName = opengames[i];
                        player.GID      = GID;
                        prox.AddGamePlayer(player);
                        ppp.username = player.UserName;
                        wrapper_TwoThree.Strategies.TryGetValue(ppp.username, out tempstrategies);
                        strategies.Add(tempstrategies);
                        wrapper_TwoThree.Strategies.Remove(player.UserName);
                        ppp.GID         = player.GID;
                        ppp.orderInGame = counterfororderofplayers++;
                        ppp.strategies.AddRange(tempstrategies);
                        wrapper_TwoThree.playerInfo.Add(ppp);
                    }

                    List <List <string> > cp = new List <List <string> >();                                             // Cartisian_Product(strategies, wrapper_TwoThree.neprofiles);

                    if (wrapper_TwoThree.playerInfo.Count > 3)                                                          //1: Start N_Player_Game
                    {
                        wrapper_TwoThree.N_Players_Game.Game_Initializr(wrapper_TwoThree.playerInfo.Count, strategies); //Strategies are ordered
                        cp.AddRange(wrapper_TwoThree.N_Players_Game.get_SetOfCStategy);                                 //Add cartesian product
                    }
                    else
                    {
                        cp = Cartisian_Product(strategies, wrapper_TwoThree.neprofiles);
                    }

                    foreach (PF p in wrapper_TwoThree.playerInfo)
                    {
                        p.CP = cp;
                    }
                    for (int i = 0; i < opengames.Count; i++)//remove the players from the queue
                    {
                        wrapper_TwoThree.Player_GameFrame_Queue.Remove(opengames[i]);
                    }
                }
                foreach (PF p in wrapper_TwoThree.playerInfo)//return this player's PF
                {
                    if (p.username == username)
                    {
                        return(p);
                    }
                }
                return(new PF());//dummy
            }
        }//RETURNS PF containing CP AND FINISHES