Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace Clones
- {
- public class CloneVersionSystem : ICloneVersionSystem
- {
- static List<Clone> clones = new List<Clone>() { new Clone() };
- class Clone
- {
- List<string> programs;
- List<string> undos;
- int number;
- internal Clone()
- {
- programs = new List<string>();
- programs.Add("basic");
- undos = new List<string>();
- number = 1;
- }
- private Clone(int num)
- {
- for (int i = 0; i < clones.Count; i++)
- {
- if (clones[i].number == num)
- {
- programs = new List<string>();
- for (int j = 0; j < clones[i].programs.Count; j++)
- {
- programs.Add(clones[i].programs[j]);
- }
- undos = new List<string>();
- for (int j = 0; j < clones[i].undos.Count; j++)
- {
- undos.Add(clones[i].undos[j]);
- }
- number = clones.Count + 1;
- break;
- }
- }
- }
- internal void Learn(string pi)
- {
- programs.Add(pi);
- while (undos.Count > 0)
- {
- undos.RemoveAt(undos.Count - 1);
- }
- }
- internal void Rollback()
- {
- var prg = programs[programs.Count - 1];
- if (prg != "basic")
- {
- undos.Add(prg);
- programs.RemoveAt(programs.Count - 1);
- }
- }
- internal void Relearn()
- {
- if (undos.Count > 0)
- {
- programs.Add(undos[undos.Count - 1]);
- undos.RemoveAt(undos.Count - 1);
- }
- }
- internal void Clonefy()
- {
- Clone clone = new Clone(number);
- clones.Add(clone);
- }
- internal string Check()
- {
- return programs[programs.Count - 1];
- }
- }
- public string Execute(string query)
- {
- string[] tokens = query.Split(' ');
- int numClone = int.Parse(tokens[1]) - 1;
- switch (tokens[0])
- {
- case "learn":
- clones[numClone].Learn(tokens[2]);
- break;
- case "rollback":
- clones[numClone].Rollback();
- break;
- case "relearn":
- clones[numClone].Relearn();
- break;
- case "clone":
- clones[numClone].Clonefy();
- break;
- case "check":
- return clones[numClone].Check();
- }
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement