
Observation 4
By Daerax ,
- Read more...
-
- 0 comments
- 378 views
By Daerax ,
var sourceFilesbyExtensions = new List();
//list of allowed extentions (e.g. cs, cpp, etc)
fileTypes.ForEach (ext => sourceFilesbyExtensions.Add(System.IO.Directory.GetFiles(folder, "*"+ext, searchOp )));
var statsOfNodes = sourceFilesbyExtensions.Select(
sourceFilesArray => sourceFilesArray.Select(sourceFile =>
{ var fn = new FileNode();
fn.Name = Path.GetFileName(sourceFile);
fn.Path = sourceFile; fn.ChildNodes.Add(fn);
CountFile(fn);
return Count(fn, (new StringBuilder()), (new StringBuilder()), (new FileNode()));
}).ToList()).ToList ();
var undistinguishedNodeStats = statsOfNodes.Aggregate((p, q) => p.Concat(q).ToList());
Summary = undistinguishedNodeStats.Aggregate("", (s, n) => n.summary + s);
public void CalculateFromFolder(string folder, bool allDirectories)
{
var searchOp = (allDirectories) ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
var sourceFilesbyExtensions = new List();
fileTypes.ForEach (ext => sourceFilesbyExtensions.Add(System.IO.Directory.GetFiles(folder, "*"+ext, searchOp )));
var statsOfNodes = sourceFilesbyExtensions.Select(
sourceFilesArray => sourceFilesArray.Select(sourceFile =>
{ var fn = new FileNode();
fn.Name = Path.GetFileName(sourceFile);
fn.Path = sourceFile; fn.ChildNodes.Add(fn);
CountFile(fn);
return Count(fn, (new StringBuilder()), (new StringBuilder()), (new FileNode()));
}).ToList()).ToList ();
var ssb = new StringBuilder();
var undistinguishedNodeStats = statsOfNodes.Aggregate((p, q) => p.Concat(q).ToList());
CodeLines = undistinguishedNodeStats.Sum(n => n.CodeLines);
Comments = undistinguishedNodeStats.Sum(n => n.Comments );
BlankLines = undistinguishedNodeStats.Sum(n => n.BlankLines);
TotalLines = undistinguishedNodeStats.Sum(n => n.TotalLines);
Summary = undistinguishedNodeStats.Aggregate("", (s, n) => n.summary + s);
CsvOutput = undistinguishedNodeStats.Aggregate("", (s, n) => n.csvOut + s);
statsOfNodes.ForEach(fileNodes => {
if (fileNodes.Count > 0) {
var codeLines = fileNodes.Sum(n => n.CodeLines);
var totalLine = fileNodes.Sum(n => n.TotalLines);
ssb.AppendFormat("{0} files, Count {1}, Total Lines {2}, Code Lines {3} [Percentage: {4} %]",
Path.GetExtension(fileNodes[0].Path), fileNodes.Count,
totalLine, codeLines, Math.Round((double)codeLines/CodeLines * 100),1); ssb.AppendLine ("\r\n");}
});
Summary += ssb.ToString();
}
if (textBoxUrl.Text == "")
{
if (File.Exists(infFilePath))
{
var urlFromFile = System.IO.File.ReadAllText(infFilePath); textBoxUrl.Text = urlFromFile;
return (urlFromFile == "") ? "https://www.gamedev.net/community/forums/mod/journal/journal.asp?jn=251283" : urlFromFile;
}
else
{
textBoxUrl.Text = "https://www.gamedev.net/community/forums/mod/journal/journal.asp?jn=251283";
return textBoxUrl.Text ;}
}
else
return textBoxUrl.Text;
var currentCheck = (currentCheckInit.Count > checkCompare.Count) && checkCompare.Count>0 ?
currentCheckInit.Skip(currentCheckInit.Count - checkCompare.Count).ToList()
: currentCheckInit;
var sb = new StringBuilder();
if (currentCheck.Sum(p => p.CommentCount) != checkCompare.Sum(p => p.CommentCount))
{
for (int i = 0; i < checkCompare.Count; i++)
{
if (currentCheck.IsComment && currentCheck.CommentCount != checkCompare.CommentCount)
{
var msg = "At " + DateTime.Now.ToShortTimeString() + " Found "
+ (currentCheck.CommentCount - checkCompare.CommentCount)
+ " New Comment(s) in thread, " + checkCompare[i - 1].Title;
listBoxLog.Items.Add(msg);
sb.AppendLine(msg);
newComment = true;
notifyIcon1.Text = "New Comment(s) found";
}
}
}
private void buttonSaveState_Click(object sender, EventArgs e)
{
var sb = new StringBuilder();
oldCheck.ForEach(entry => sb.AppendLine (entry.CommentCount + "|"+entry.IsComment + "|" +entry.Title));
File.WriteAllText(statePath, sb.ToString());
}
private void buttonCompareStates_Click(object sender, EventArgs e)
{
var urlFromFile = System.IO.File.ReadAllText(infFilePath);
if ((urlFromFile != textBoxUrl.Text) && textBoxUrl.Text != "")
MessageBox.Show("Warning Url found in file and in textbox do not match. This *may* cause discrapncies.",
"Are you Sure you know what you are doing?",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
var tmpCheck = new List();
var dat = File.ReadAllLines(statePath).ToList ();
dat.ForEach(item => { var s = item.Split('|');
var newE = new JournalEntry();
newE.CommentCount = int.Parse(s[0]);
newE.IsComment = bool.Parse(s[1]);
newE.Title = s[2];
tmpCheck.Add(newE); });
var currentCheck = util.PollGDNEt(CheckUrlOptions());
inited = true;
DoComparison(currentCheck, tmpCheck);
}
public static ListPollGDNEt(string url)
{
HtmlWeb page = new HtmlWeb();
HtmlDocument doc = page.Load(url);
var xdoc = doc.ToXDocument();
var queryResults = from element in xdoc.Descendants()
where element.HasAttributes
&& element.Name.LocalName == "span"
&& (element.FirstAttribute.Value == "regularfont" || (element.FirstAttribute.Value == "smallfont" && element.Value.Contains("Comments")))
select new {Title = element.Value,
IsComment = element.FirstAttribute.Value == "smallfont",
Count = element.FirstAttribute.Value == "smallfont" ?
int.Parse( Regex.Match( element.Value, @"\d+").Value ) : 0 };
var Entries = new List();
foreach (var result in queryResults)
{
var entry = new JournalEntry ();
entry.CommentCount = result.Count; entry.IsComment = result.IsComment ; entry.Title = result.Title ;
Entries.Add(entry);
}
return Entries;
}
User | Total comments on Page | Avg Comments Per Post | Total Posts
-------------------------------------------------------------------------------------------------------
TrapperZoid 20 4 5
Drew 19 1.27 15
Talestyn 16 1.07 15
Ben 16 2 8
Ravuya 16 1.14 14
Me 6 1.2 5
By Daerax ,
Quote:I wonder what it says on the culture and views held of said people. If it shows cultural maturity or disdain of education and book learning amongst males.
In 1992, women [in Bulgaria] obtained 57 percent of all university degrees. In addition, they obtained half of the engineering degrees, 70 percent of the natural science degrees, and 73 percent of the mathematics and computer science degrees. These percentages have not changed since 1975 (Stretenova, 1994). (See "http://www.nsf.gov/statistics/nsf96316/figs/txtfig12.gif")
items = [
{'name' : "Bronze Sword", 'value' : 50, 'diceCount' : 1, 'diceSides' : 4},
{'name' : "Steel Sword", 'value' : 100, 'diceCount' : 2, 'diceSides' : 4},
{'name' : "Adamantium Sword", 'value' : 200, 'diceCount' : 1, 'diceSides' : 10}
]
result = [item for item in items if item['value'] > 50]
print result
#light
type Item = {name : string; value : int; diceCount: int; diceSides : int}
let items = [
{name = "Bronze Sword"; value = 50; diceCount = 1; diceSides = 4};
{name ="Steel Sword"; value = 100; diceCount = 2; diceSides = 4};
{name = "Adamantium Sword"; value = 200; diceCount = 1 ;diceSides = 10}
]
let result = [for item in items when item.value > 50 -> item ]*
print_any result
def CheckFits( o, c, s, s2){
if ( (o + s2 - c > 0) && (o - c < s))
true
else
false
}
def partitioned_tree = Tree.Partition( visualization_tree ,
fun(o){
if ( CheckFits(o.Position.X, camera.Location.X,Nsdl.ScreenRes.Width, o.Size.Width ) &&
CheckFits(o.Position.Y, camera.Location.Y,Nsdl.ScreenRes.Height, o.Size.Height ))
true
else
false
});
def (visibleObjects, _) = partitioned_tree;
def (actors, nonActors) = Tree.Partition (visibleObjects,
fun(o) {
match(o.VisualType ) {
| VisualType.AnimatedAndActs => true
| _ => false }
});
seq [ (obj.Position, obj.CurrentAnimation) = (pos, dir.ToString ()) ,
obj in actors, obj.AbstractPart.Act(obj.Position, obj.Size) -> (pos, dir) ];
mutable FinalTree = nonActors;
seq [ FinalTree = Tree.Insert(FinalTree, actor, false), actor in actors];
FinalTree;
def objs = [GameObject(@".\Art\014.bmp", Drawing.Point(480,250), Drawing.Color.FromArgb (255,255,255), VisualType.Static() ),
GameObject(@".\Art\stand2.png", Drawing.Point(920,300),Drawing.Color.FromArgb (200,140,208), VisualType.Static(), 1.0f ),
GameObject(@".\Art\tavernx.bmp", Drawing.Point(420,260),Drawing.Color.FromArgb (200,140,208), VisualType.Static(), 1.0f )] ;
def o1 = GameObject(@".\Art\017.bmp",Drawing.Color.FromArgb (255,255,255), VisualType.Static() );
def ao = GameObject(@".\Art\Animations\BlueJet", Color.FromArgb (2, 9,124), VisualType.Animated(), 2.0f);
def ao2 = GameObject(@".\Art\Animations\earthmagic muni", Color.FromArgb (204, 173,97), VisualType.AnimatedAndActs(), 3.0f);
ao2.FilterAnims = [("North","earthmagic muni n "),("South","earthmagic muni s"),("East","earthmagic muni e"),
("West","earthmagic muni w"),("NorthEast","earthmagic muni ne"),("SouthEast","earthmagic muni se"),
("NorthWest","earthmagic muni nw"),("SouthWest","earthmagic muni sw") ];
ao2.AbstractPart = MovingAnimatedObject();
def w = World(@".\Art\012.bmp");
seq [ w.AddObject (o) , o in objs];
w.AddObject(ao);
w.AddObject(ao2);
w.AddObjectManyTimes(o1, World.RandomDistribution(95, 500));
_ = Narrator(w);
ActOn ( v : VisualAspect ) : Sprites.Sprite
match(v.VisualType )
| VisualType.Animated => def animSprite = Sprites.AnimatedSprite(Nsdl.LoadBitmapAsAnimation(v.Key , v.FurtherFlags, v.Transcolor));
animSprite.Animate = true;
animSprite ;
| VisualType.Static => Sprites.Sprite(Nsdl.LoadBitmap(v.Key, v.Transcolor ));
....
seq[ { o.Size = bmp.Size ;
unless(surfacePool.Contains(o.Key))
surfacePool = surfacePool.Add(o.Key, bmp) } ,
o in TheWorld.VisualizationTree, ActOn(o) -> bmp
def objs = [VisualAspect(@".\Art\014.bmp", Drawing.Point(480,250), Drawing.Color.FromArgb (255,255,255), VisualType.Static() ),
VisualAspect(@".\Art\stand2.png", Drawing.Point(920,300),Drawing.Color.FromArgb (200,140,208), VisualType.Static() ),
VisualAspect(@".\Art\tavernx.bmp", Drawing.Point(420,260),Drawing.Color.FromArgb (200,140,208), VisualType.Static(), 2.0f )] ;
def o1 = VisualAspect(@".\Art\017.bmp",Drawing.Color.FromArgb (255,255,255), VisualType.Static() );
def ao = VisualAspect(@".\Art\Animations\BlueJet", Color.FromArgb (2, 9,124), VisualType.Animated(), 2.0f);
seq [ w.AddObject (o) , o in objs];
w.AddObject(ao);
w.AddObjectManyTimes(o1, World.RandomDistribution(95, 500));
strip (z : option[Surface]) : Surface
match(z)
| Some(s) => s
| None => base_gfx
public Display() : void
seq [ _ = video.Blit(base_gfx,Drawing.Point(x,y)),
x in [0,base_gfx.Width..video.Width ], y in [0,base_gfx.Height..video.Height]];
seq[ _ = video.Blit (surface , Drawing.Point(p.X - camera.Location.X, p.Y - camera.Location.Y)),
o in TheWorld.BuildVisibleList(), strip(surfacePool.Find ( o.Key)) -> surface,
o.Position -> p ];
video.Update ();
public AddObject(o : ObjectType ) : void {
objects = Tree.Insert(objects,o,false);
}
public BuildVisibleList () : list[ObjectType] {
def CheckFits( o, c, s, s2){
if ( (o + s2 - c > 0) && (o - c < s))
true
else
false }
objects.Filter( fun(o){
if ( CheckFits(o.Position.X, camera.Location.X,Nsdl.ScreenRes.Width, o.Size.Width ) &&
CheckFits(o.Position.Y, camera.Location.Y,Nsdl.ScreenRes.Height, o.Size.Height ))
true
else
false
}); }
Main() : void
def objs = [ObjectType(@".\Art\014.bmp", Drawing.Point(480,250), Drawing.Color.FromArgb (255,255,255)),
ObjectType(@".\Art\stand2.png", Drawing.Point(920,300),Drawing.Color.FromArgb (200,140,208)),
ObjectType(@".\Art\tavernx.bmp", Drawing.Point(420,260),Drawing.Color.FromArgb (200,140,208), 2.0f)] ;
def o1 = ObjectType(@".\Art\017.bmp",Drawing.Color.FromArgb (255,255,255));
def w = World(@".\Art\012.bmp");
seq [ w.AddObject (o) , o in objs];
w.AddObjectManyTimes(o1, World.RandomDistribution(95, 500));
_ = Narrator(w);
By Daerax ,
. Narrator
. SDL
. Camera
. World
. Objects ------- Objects can have properties, some can:
- move
- change shape or form
- make sounds
- resist movement
- some combination of or all of the above
guess = NextRandom 200.0;
Print "Guess a number between 0 and 200\n\n";
letrec game : float -> float -> unit =
function r : float | tries : float.
if r == guess then ( Print "Got It. Took: " ; Print tries; Print " tries.")
else (
if r > guess then
Print "Too High, Try again...\n"
else
Print "Too Low, Try again...\n" ;
game (Convert ReadInput To float) (tries + 1.0)
)
in game (Convert ReadInput To float) 0.0;
z = while (@k) < 2.0 do r <- @k * @r ; @k;is whatever value k was at the end of the loop. The evaluation takes on average .5 seconds which is quite a bit slower than the other but alot more is going on as I will explain in a future post. However I am also counting the file loading and pretty printing which probable adds quite a bit.
val = mutable_cell 0.0;
den = mutable_cell 1.0;
isplus = mutable_cell true;
one = mutable_cell 1.0;
while (@den) < 10000.0 do (
val <- (@val) + (@one) * (4.0 / (@den));
den <- (@den) + -2.0;
one <- neg (@one)
);
////////////////////////////////
- = function a : float | b : float . a + -b;
not b = fun a : bool . if a then false else true;
pi = while (@den) < 10000.0 do (
if (@isplus) then
val <- (@val) + (4.0 / (@den))
else
val <- (@val) [-] (4.0 / (@den)) ;
den <- (@den) + 2.0;
isplus <- not (@isplus) ;
@val
);
Print pi;
By Daerax ,
pi = rec ( function pi den val one .
if den < 1000.0 then
pi (den + 2.0) (val + one * (4.0 / den)) (neg one)
else
val );
pi 1.0 0.0 1.0 //3.13959265558979
r = "20";
game = rec (function game guess.
if r == guess then
"Got It"
else
game ReadInput));
"Guess the number: ";
guess = ReadInput;
game guess;
factorial = rec ( fun fct . fun n .
if n == 0.0 then
1.0
else
n * (fct (n + -1.0)) );
% = fun a . fun b . a mod b;
5 [%] 3; // 2
(% 5 3) // or use it lisp style. :s
This works for all functions. so i can go:
mix = fun a . fun b . a * b + a;
2 [mix] 3 // 8
By Daerax ,
prod = fun x. fun y. addf x (mulf x y); /* x + y*x */
partapply = prod 4.0;
r = partapply 2.0; /* 12 */
k = prod 4.0 3.0; /* 16 */
zk = "BOO:";
ss = "lllp";
id = fun x.x;
id zk;
when = fun b . fun x . if b then x else false;
when true (
(fun x . x) ("Id is: " 5) );
p = 5 zk ss; /* */
"P is : " p; /*prints ("P is : " (5 "BOO:" ss))*/
p = 5 (zk ss); /*("P is : "(5("BOO:" "lllp")))*/
By Daerax ,
x#; /*bind a variable to the context*/
y#;
x (y x); /* everything is a function */
fun z.z y; /* apply y to fun z -> z */
fun x.x; /* identity function */
fun t. fun f . f; /* boolean false */
(fun x.x) (fun x. x x) y;
By Daerax ,
isPlus := true;
denominator := 1.0;
val := 0.0;
while denominator < 10000.0 do
begin
if isPlus then
val := val + (4.0 / denominator)
else
val := val - (4.0 / denominator);
isPlus := Not isPlus;
denominator := denominator + 2.0
end;
print val
////////////////////////
Began at: 07/08/2008 20:36:58
: False
TFloat 3.141392654
Finished at: 07/08/2008 20:36:58 Interval: 00:00:00.1093750
run
Began at: 07/08/2008 20:36:59
: False
TFloat 3.141392654
Finished at: 07/08/2008 20:36:59 Interval: 00:00:00.0937500
raining := 0.4;
cloudy := 0.7;
shining := 0.2;
if raining Or shining => cloudy <=> 1.0 then print 200;
print raining Or shining => cloudy
Began at: 07/08/2008 20:43:36
TInteger 200 TFloat 1.0
Finished at: 07/08/2008 20:43:36 Interval
print true ^ 20; print 2 ^ 20;
Error near line 0, character 30
Try one of: print ; quit; trycounter; t
ue | false; =>, ^, Or, Not, <=>
TTriv False
Input: print true ^ 20; print 2 ^ 20
TTriv Mu TFloat 1048576.0
Input: print 2 < true
TTriv Mu
let (===>) a b =
match (a, b) with
(True ,x) -> x
| (False , _) -> True
| (Mu , False) -> Mu
| (Mu, x) -> True
let (|||) a b =
match (a, b) with
(True , _ ) -> True
| (False , x) -> x
| (Mu , True) -> True
| (Mu , _ ) -> Mu
let (&&&) a b =
match (a, b) with
(True , x) -> x
| (False , _) -> False
| (Mu , False) -> False
| (Mu , _) -> Mu
Input: Raining := true ; Shining := mu;
Cloudy := true; dry := false;
print Raining ^ Cloudy <=> Not Shining
Mu
Input: print Raining ^ Cloudy => Not Shining Or Cloudy
True
Input:
type expr =
| Val of string
| Bool of bool
| And of expr * expr
| Or of expr * expr
| Implies of expr * expr
| Not of expr
| Equiv of expr * expr
//with where a some rules have been given to lexer e.g.:
rule token = parse
| whitespace { token lexbuf }
| newline { (lexbuf: lexbuf).EndPos <- lexbuf.EndPos.NextLine; token lexbuf }
| "(" { LPAREN }
| ")" { RPAREN }
| "^" { AND }
| "Or" { OR }
| "=>" { IMPLIES }
....
//Or Parser :
Expr: ID { Val $1 }
| BOOL { Bool $1 }
| Expr AND Expr { And ($1, $3) }
| Expr OR Expr { Or ($1, $3) }
...
//And Interpreter in source via Match:
let rec evalE (env: Mapbool>) = function
| Val v -> if env.ContainsKey v then env.[v]
else System.Console.WriteLine("\nDefaulting to true for unbound variable: " + v); true
| Bool b -> b
| And (e1, e2) -> evalE env e1 && evalE env e2
....
raining := true; Cloudy := true;Cloudy and shining implies raining and shining and not cloudy.
Shining := Not raining //You can then go something like
"print (raining Or (Cloudy ^ Shining)) => (Not Shining ^ raining) Or (raining ^ Shining)"// to get err let me check ... true
Another true prop:
print (Cloudy ^ Shining) => (raining ^ Shining ^ Not Cloudy)
tautology p => q <=> p => q ^ q => p is given as true.. That is all for now after a few hours work.
Input: xorab = a Or Not b Or not b Or a; tautology a Or xorab ^ p Or xorab.
. Decided on simpler queries. e.g r := true. istrue q ^ p in p => q Or r. Simply breaks down expression after 'in' where searches for each in environment. else left alone. Then substitute each occurrence of bounded variables with values. Then for each variable after istrue extract table, if the union of all such vars is true then q ^ p is true. For example: in p ^ q Or r ^ q and defined r := true. Then it will tell you that q must also be true but p is unknown."EStore in pq exp p => q as true"; p := true. VStore p; tryprove q in pq
By Daerax ,
def z = vec n //where the type of n is known at compile time and hence the size of z
[Enforce n < 50 && m - n != 0]
method(n : Natural , m : Natural, o : int, v : vec 5 )
dtype n + 50 {}
/*<-- dtype types the method and also the parameters and adds the neceassary type variables.
Writing method[a,b,c,d] (n : Natural[a], ...) is cumbersome. All statically checked with phantoms.*/
{
}
template m> class Monad
{
virtual Monad< a > Bind( m, ... ) = 0; //dont know how to write functions in C++ or if virtual is appropriate in a templated class>?
};
class Maybe : Monad{... }// ?
By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.
Participate in the game development conversation and more when you create an account on GameDev.net!
Sign me up!