Exemple #1
0
        public void LoadlongTermMermory(String file)
        {
            NeaReader reader = new NeaReader(new StreamReader(file + ".MQ"));

            while (reader.Peek() != -1)
            {
                List <VirusMemory> memories   = new List <VirusMemory>();
                VirusBoard         startState = new VirusBoard();
                VirusBoard         endState   = new VirusBoard();
                Move   action = new Move();
                double reward;
                double significance;
                string data;

                data = reader.ReadLine();
                NeaReader r = new NeaReader(data);
                significance = double.Parse(r.ReadUntil(":"));
                while (r.Peek() != -1)
                {
                    startState.Load(r.ReadUntil(":"));
                    endState.Load(r.ReadUntil(":"));
                    action.Load(r.ReadUntil(":"));
                    reward = double.Parse(r.ReadUntil(":"));
                    memories.Add(new VirusMemory(startState, action, endState, reward));
                }


                //memory = new VirusMemory(startState, action, endState, reward);
                LongTermMemory.Add(new VirusMemoryEpisode(memories.ToArray(), significance));                //new VirusLongTermMemory(memory, significance));
            }
            reader.Close();
        }
Exemple #2
0
        public void Load(string save)
        {
            NeaReader reader = new NeaReader(save);

            sx = reader.ReadInt();
            sy = reader.ReadInt();
            ex = reader.ReadInt();
            ey = reader.ReadInt();
        }
Exemple #3
0
        public static bool TryParseDisconnectMessage(string message, out string id)
        {
            id = "";
            bool success = InitialMessageCheck(message, MessageType.Disconnect, out message);

            if (!success)
            {
                return(false);
            }

            NeaReader reader = new NeaReader(message);

            try {
                id = reader.ReadWord();
            }
            catch { return(false); }
            return(true);
        }
Exemple #4
0
        public void Load(string save)
        {
            NeaReader reader = new NeaReader(save);

            players = byte.Parse(reader.ReadUntil(";"));
            winner  = byte.Parse(reader.ReadUntil(";"));
            int size = int.Parse(reader.ReadUntil(";"));

            board = new byte[size, size];

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    board[i, j] = byte.Parse(reader.ReadWord());
                }
            }
        }
Exemple #5
0
        private void ProcessEntry(NeaReader reader)
        {
            String[] fields = new String[fieldcount];
            for (int i = 0; i < fieldcount; i++)
            {
                fields[i] = reader.ReadUntilAny(";");
                if (reader.Peek() == -1)
                {
                    return;
                }
            }
            int month;
            int year;

            try {
                String smonth = fields[datefield].Substring(3, 2);
                String syear  = fields[datefield].Substring(6, 2);
                month = int.Parse(smonth) - 1;
                year  = int.Parse(syear) + 2000;
                if (month < 4)
                {
                    year--;
                }

                //make month 0 be May, and month 11 be April
                month -= 4;
                if (month < 0)
                {
                    month += 12;
                }
            }
            catch (Exception e) {
                return;
            }
            YearInfo y = GetYear(year);

            if (y == null)
            {
                y = new YearInfo(year);
                years.Add(y);
            }
            y.AddEntry(month, fields);
        }
Exemple #6
0
        public static bool TryParseReadyMessage(string message, out string id, out bool ready)
        {
            id    = "";
            ready = false;
            bool success = InitialMessageCheck(message, MessageType.Ready, out message);

            if (!success)
            {
                return(false);
            }

            NeaReader reader = new NeaReader(message);

            try {
                id    = reader.ReadWord();
                ready = reader.ReadInt() == 1 ? true : false;
            }
            catch { return(false); }
            return(true);
        }
Exemple #7
0
        public static bool TryParseNameMessage(string message, out string id, out string name)
        {
            id   = "";
            name = "";
            bool success = InitialMessageCheck(message, MessageType.Name, out message);

            if (!success)
            {
                return(false);
            }

            NeaReader reader = new NeaReader(message);

            try {
                id   = reader.ReadWord();
                name = reader.ReadSection('[', ']');
            }
            catch { return(false); }
            return(true);
        }
Exemple #8
0
        public static bool TryParseColorMessage(string message, out string id, out Color color)
        {
            id    = "";
            color = Color.Red;
            bool success = InitialMessageCheck(message, MessageType.Color, out message);

            if (!success)
            {
                return(false);
            }

            NeaReader reader = new NeaReader(message);

            try {
                id    = reader.ReadWord();
                color = Color.FromName(reader.ReadWord());
            }
            catch { return(false); }
            return(true);
        }
Exemple #9
0
        public void LoadFile(string file, StartUpWindow startwindow)
        {
            bool success = true;

            try {
                NeaReader reader = new NeaReader(new StreamReader(file));
                reader.ReadLine();
                while (reader.Peek() != -1 && !shouldstop)
                {
                    ProcessEntry(reader);
                }
                reader.Close();
            }
            catch (Exception e) {
                success = false;
            }
            if (!shouldstop)
            {
                startwindow.Dispatcher.BeginInvoke(new Action(() => { startwindow.FinishedLoading(success); }));
            }
        }
Exemple #10
0
        public static bool TryParseGameMessage(string message, out string id, out int x, out int y, out int dx, out int dy)
        {
            id = "";
            x  = y = dx = dy = 0;
            bool success = InitialMessageCheck(message, MessageType.GameMessage, out message);

            if (!success)
            {
                return(false);
            }

            NeaReader reader = new NeaReader(message);

            try {
                id = reader.ReadWord();
                x  = reader.ReadInt();
                y  = reader.ReadInt();
                dx = reader.ReadInt();
                dy = reader.ReadInt();
            }
            catch { return(false); }
            return(true);
        }
Exemple #11
0
        public static bool TryParseStartGameMessage(string message, out string[] sequence)
        {
            sequence = new string[0];
            bool success = InitialMessageCheck(message, MessageType.StartGame, out message);

            if (!success)
            {
                return(false);
            }

            NeaReader reader = new NeaReader(message);

            try {
                List <string> list = new List <string>();
                reader.SkipWhiteSpace();
                while (reader.Peek() != -1)
                {
                    list.Add(reader.ReadWord());
                }
                sequence = list.ToArray();
            }
            catch { return(false); }
            return(true);
        }
Exemple #12
0
		public static bool TryParseStartGameMessage(string message, out string[] sequence) {
			sequence = new string[0];
			bool success = InitialMessageCheck(message, MessageType.StartGame, out message);
			if (!success)
				return false;

			NeaReader reader = new NeaReader(message);

			try {
				List<string> list = new List<string>();
				reader.SkipWhiteSpace();
				while (reader.Peek() != -1) {
					list.Add(reader.ReadWord());
				}
				sequence = list.ToArray();
			}
			catch { return false; }
			return true;
		}
Exemple #13
0
		public static bool TryParseDisconnectMessage(string message, out string id) {
			id = "";
			bool success = InitialMessageCheck(message, MessageType.Disconnect, out message);
			if (!success)
				return false;

			NeaReader reader = new NeaReader(message);

			try {
				id = reader.ReadWord();
			}
			catch { return false; }
			return true;
		}
Exemple #14
0
        private void LoadDepFiles()
        {
            //string[] filePaths = null;
            string file = null;

            departments = new Dictionary <string, string[]>();
            //config data
            try
            {
                file = "Personale liste Know How.txt";
                NeaReader r = new NeaReader(new StreamReader(file));
                while (r.Peek() != -1)
                {
                    char next = (char)r.Peek();
                    while (char.IsWhiteSpace(next))
                    {
                        r.ReadLine();
                        next = (char)r.Peek();
                    }

                    string        departmentname = "ERROR";
                    List <string> strings        = new List <string>();

                    while (r.Peek() != -1)
                    {
                        next = (char)r.Peek();
                        if (!char.IsWhiteSpace(next))
                        {
                            if (departmentname != "ERROR")
                            {
                                departments.Add(departmentname, strings.ToArray());
                                strings.Clear();
                            }
                            departmentname = r.ReadWord().ToUpper();
                            r.ReadLine();
                        }
                        else
                        {
                            r.SkipWhiteSpace();
                            r.ReadUntil('\t');                             //løn nr
                            r.SkipWhiteSpace();
                            r.ReadUntil('\t');                             // efternavn
                            r.SkipWhiteSpace();
                            r.ReadUntil('\t');                             // fornavn
                            r.SkipWhiteSpace();
                            r.ReadUntil('\t');                             // afdeling
                            if (r.Peek() == -1)
                            {
                                break;
                            }
                            r.SkipWhiteSpace();
                            brugernavn = r.ReadWord();                             // brugernavn
                            strings.Add(brugernavn.ToUpper());

                            r.ReadLine();
                        }
                    }
                    departments.Add(departmentname, strings.ToArray());
                }
                r.Close();
            }
            catch (FileNotFoundException fnf)
            {
                StreamWriter w = new StreamWriter("Personale liste Know How.txt");
                w.Write("Fill this with data");
                w.Close();
            }
            catch (Exception e)
            {
            }

            foreach (string afdeling in departments.Keys)
            {
                combobox_Afd.Items.Add(afdeling);
            }
            combobox_Afd.Items.Add("ALLE AFDELINGER");
        }
Exemple #15
0
		public static bool TryParseReadyMessage(string message, out string id, out bool ready) {
			id = "";
			ready = false;
			bool success = InitialMessageCheck(message, MessageType.Ready, out message);
			if (!success)
				return false;

			NeaReader reader = new NeaReader(message);

			try {
				id = reader.ReadWord();
				ready = reader.ReadInt() == 1 ? true : false;
			}
			catch { return false; }
			return true;
		}
Exemple #16
0
		public static bool TryParseNameMessage(string message, out string id, out string name) {
			id = "";
			name = "";
			bool success = InitialMessageCheck(message, MessageType.Name, out message);
			if (!success)
				return false;

			NeaReader reader = new NeaReader(message);

			try {
				id = reader.ReadWord();
				name = reader.ReadSection('[', ']');
			}
			catch { return false; }
			return true;
		}
Exemple #17
0
		public static bool TryParseColorMessage(string message, out string id, out Color color) {
			id = "";
			color = Color.Red;
			bool success = InitialMessageCheck(message, MessageType.Color, out message);
			if (!success)
				return false;

			NeaReader reader = new NeaReader(message);

			try {
				id = reader.ReadWord();
				color = Color.FromName(reader.ReadWord());
			}
			catch { return false; }
			return true;
		}
Exemple #18
0
		public void LoadlongTermMermory(String file)
		{
			NeaReader reader = new NeaReader(new StreamReader(file + ".MQ"));

			while (reader.Peek() != -1)
			{
				List<VirusMemory> memories = new List<VirusMemory>();
				VirusBoard startState = new VirusBoard();
				VirusBoard endState = new VirusBoard();
				Move action = new Move();
				double reward;
				double significance;
				string data;

				data = reader.ReadLine();
				NeaReader r = new NeaReader(data);
				significance = double.Parse(r.ReadUntil(":"));
				while (r.Peek() != -1) {
					startState.Load(r.ReadUntil(":"));
					endState.Load(r.ReadUntil(":"));
					action.Load(r.ReadUntil(":"));
					reward = double.Parse(r.ReadUntil(":"));
					memories.Add(new VirusMemory(startState, action, endState, reward));
				}
				

				//memory = new VirusMemory(startState, action, endState, reward);
				LongTermMemory.Add(new VirusMemoryEpisode(memories.ToArray(), significance));//new VirusLongTermMemory(memory, significance));
			}
			reader.Close();
		}
        private void LoadDefaultFiles()
        {
            string[] filePaths = null;
            string   file      = "config.ini";

            //config data
            try {
                NeaReader     r     = new NeaReader(new StreamReader(file));
                ReadState     state = ReadState.FindNextEntry;
                string        group = "ERROR";
                List <string> list  = new List <string>();

                while (r.Peek() != -1)
                {
                    NeaReader line = new NeaReader(r.ReadLine());
                    string    temp;

                    line.SkipWhiteSpace();
                    if ((char)line.Peek() == '#')                     // comment
                    {
                        continue;
                    }

                    switch (state)
                    {
                    case ReadState.FindNextEntry:
                        temp = line.ReadWord();
                        if (temp == "Group:")
                        {
                            line.SkipWhiteSpace();
                            group = line.ReadToEnd();
                            state = ReadState.FindNextKGM;
                        }
                        else if (temp == "Ratio:")
                        {
                            string[] ratio = new string[2];
                            ratio[0] = line.ReadSection('[', ']');
                            ratio[1] = line.ReadSection('[', ']');
                            ratios.Add(ratio);
                        }
                        break;

                    case ReadState.FindNextKGM:
                        line.SkipWhiteSpace();
                        if (line.Peek() != -1)
                        {
                            list.Add(line.ReadWord());
                        }
                        else
                        {
                            groups.Add(group, list.ToArray());
                            list.Clear();
                            state = ReadState.FindNextEntry;
                        }
                        break;
                    }
                }
                r.Close();
            }
            catch (FileNotFoundException fnf) {
                StreamWriter w = new StreamWriter("config.ini");
                w.Write("Fill this with data");
                w.Close();
            }
            catch (Exception e) {
            }
            filePaths = null;
            file      = null;
            //ranking data
            try {
                filePaths = Directory.GetFiles("rankingdata//", "*.csv");
            }
            catch (Exception e) {
            }
            if (filePaths != null)
            {
                if (filePaths.Length == 1)
                {
                    file = filePaths[0];
                }
            }

            if (file == null)
            {
                SetText(StatusText, "Ingen fil fundet.\nVælg venligst en at indlæse.");
                Dispatcher.BeginInvoke(new Action(() => {
                    LoadButton.IsEnabled = true;
                }));
            }
            else
            {
                Dispatcher.BeginInvoke(new Action(() => { LoadingProgressBar.IsIndeterminate = true; }));
                SetText(StatusText, "Indlæser filen:\n" + file);
                dataHandler = new DataHandler();
                Thread thread = new Thread(() => { dataHandler.LoadFile(file, this); });
                thread.Start();
            }
        }
Exemple #20
0
		public static bool TryParseGameMessage(string message, out string id, out int x, out int y, out int dx, out int dy) {
			id = "";
			x = y = dx = dy = 0;
			bool success = InitialMessageCheck(message, MessageType.GameMessage, out message);
			if (!success)
				return false;

			NeaReader reader = new NeaReader(message);

			try {
				id = reader.ReadWord();
				x = reader.ReadInt();
				y = reader.ReadInt();
				dx = reader.ReadInt();
				dy = reader.ReadInt();
			}
			catch { return false; }
			return true;
		}