Can someone help me improve speed?
As of now this generates a dictionary full of points that a player can
move to and the cost of that move. My problem is that it takes ages to
process.
I understand that although a square is already checked as added my method
checks the same square again, but when I dont do this than the moveable
area gets all screwed up and it does not return what it should.
Can i get some pointers on how to speed this up, Please include
examplecode. I was thinking about a few extra threads but that would leave
me processing this in quadrents and if i need to form movements around an
object on the grid then I dont think ill be able to build off of cells
belonging to other threads.
This code works right now, it is just slow as snot and its unacceptable
for my program.
Please note that This is not path finding, I am only looking for all
possible moves, not the shortest way to get to a spot.
class MoveCompiler
{
public Board Board;
public MoveCompiler(Board board)
{
Board = board;
}
Dictionary<Coordinate, int> MovesList = new Dictionary<Coordinate,
int>(new Coordinate.EqualityComparer());
public Dictionary<Coordinate, int> getMoves( int startRow, int
startColumn, int actionPointsUsed,int maxActionPoints, bool
firstDiagnol)
{
int moveCost = 1;
if (!firstDiagnol)
{
moveCost = 2;
}
if (actionPointsUsed + moveCost <= maxActionPoints)
{
if (IfCheck(startRow + 1, startColumn + 1))
{
if (!Board.cellAt(new Coordinate(startRow + 1,
(startColumn + 1))).InUse)
{
MovesList.Add(new Coordinate(startRow + 1,
(startColumn + 1)), actionPointsUsed + moveCost);
Board.cellAt(new Coordinate(startRow + 1, (startColumn
+ 1))).InUse = true;
}getMoves(startRow + 1, startColumn + 1, actionPointsUsed
+ moveCost, maxActionPoints, !firstDiagnol);
}
if (IfCheck(startRow + 1, startColumn - 1))
{
if (!Board.cellAt(new Coordinate(startRow + 1,
(startColumn - 1))).InUse)
{
MovesList.Add(new Coordinate(startRow + 1,
(startColumn - 1)), actionPointsUsed + moveCost);
Board.cellAt(new Coordinate(startRow + 1, (startColumn
- 1))).InUse = true;
}getMoves(startRow + 1, startColumn - 1, actionPointsUsed
+ moveCost, maxActionPoints, !firstDiagnol);
}
if (IfCheck(startRow - 1, startColumn - 1))
{
if (!Board.cellAt(new Coordinate(startRow - 1,
(startColumn - 1))).InUse)
{
MovesList.Add(new Coordinate(startRow - 1,
(startColumn - 1)), actionPointsUsed + moveCost);
Board.cellAt(new Coordinate(startRow - 1, (startColumn
- 1))).InUse = true;
}getMoves(startRow - 1, startColumn - 1, actionPointsUsed
+ moveCost, maxActionPoints, !firstDiagnol);
}
if (IfCheck(startRow - 1, startColumn + 1))
{
if (!Board.cellAt(new Coordinate(startRow - 1,
(startColumn + 1))).InUse)
{
MovesList.Add(new Coordinate(startRow - 1,
(startColumn + 1)), actionPointsUsed + moveCost);
Board.cellAt(new Coordinate(startRow - 1, (startColumn
+ 1))).InUse = true;
}getMoves(startRow - 1, startColumn + 1, actionPointsUsed
+ moveCost, maxActionPoints, !firstDiagnol);
}
}
if (actionPointsUsed + 1 <= maxActionPoints)
{
if (IfCheck(startRow - 1, startColumn))
{
if (!Board.cellAt(new Coordinate(startRow - 1,
(startColumn))).InUse)
{
MovesList.Add(new Coordinate(startRow - 1,
(startColumn)), actionPointsUsed + moveCost);
Board.cellAt(new Coordinate(startRow - 1,
(startColumn))).InUse = true;
}getMoves(startRow - 1, startColumn, actionPointsUsed + 1,
maxActionPoints, firstDiagnol);
}
if (IfCheck(startRow + 1, startColumn))
{
if (!Board.cellAt(new Coordinate(startRow + 1,
(startColumn))).InUse)
{
MovesList.Add(new Coordinate(startRow + 1,
(startColumn)), actionPointsUsed + moveCost);
Board.cellAt(new Coordinate(startRow + 1,
(startColumn))).InUse = true;
}getMoves(startRow + 1, startColumn, actionPointsUsed + 1,
maxActionPoints, firstDiagnol);
}
if (IfCheck(startRow, startColumn + 1))
{
if (!Board.cellAt(new Coordinate(startRow, (startColumn +
1))).InUse)
{
MovesList.Add(new Coordinate(startRow, (startColumn +
1)), actionPointsUsed + moveCost);
Board.cellAt(new Coordinate(startRow, (startColumn +
1))).InUse = true;
}getMoves(startRow, startColumn + 1, actionPointsUsed + 1,
maxActionPoints, firstDiagnol);
}
if (IfCheck(startRow, startColumn - 1))
{
if (!Board.cellAt(new Coordinate(startRow, (startColumn -
1))).InUse)
{
MovesList.Add(new Coordinate(startRow, (startColumn -
1)), actionPointsUsed + moveCost);
Board.cellAt(new Coordinate(startRow, (startColumn -
1))).InUse = true;
}getMoves(startRow, startColumn - 1, actionPointsUsed + 1,
maxActionPoints, firstDiagnol);
}
}
return MovesList;
}
private bool IfCheck(int desiredRow, int desiredColumn)
{
bool ReturnMe= false;
if (desiredRow <= Board.BOARDHEIGHT && desiredRow >= 1)
if (desiredColumn + 1 <= Board.BOARDWIDTH && desiredColumn >= 1)
if (!Board.cellAt(new Coordinate(desiredRow,
desiredColumn)).hasCharacter)
//if (!Board.cellAt(new Coordinate(desiredRow,
(desiredColumn))).InUse)
if (Board.cellAt(new Coordinate(desiredRow,
desiredColumn)).isPassable)
ReturnMe = true;
return ReturnMe;
}
private void VH()
{
}
}
Thursday, 22 August 2013
Animating the mask for a UIView
Animating the mask for a UIView
I can create a mask like this:
CALayer *mask = [CALayer layer];
mask.contents = (id)[[UIImage imageNamed:@"mask.png"] CGImage];
mask.frame = CGRectMake(0, 0, 10, 10);
self.content.layer.mask = mask;
And this will correctly reveal the top left 10 pixels of my content
(because mask.png is just a black image). However I want to animate the
mask to reveal the rest of the content:
[UIView animateWithDuration:3.0
animations:^{
mask.frame = self.content.bounds;
}
completion:^(BOOL finished){
}];
The problem is that there's no animation. The entire content gets
displayed immediately. Why does this happen, and how can I animate the
mask so that the content is revealed from the upper left?
I can create a mask like this:
CALayer *mask = [CALayer layer];
mask.contents = (id)[[UIImage imageNamed:@"mask.png"] CGImage];
mask.frame = CGRectMake(0, 0, 10, 10);
self.content.layer.mask = mask;
And this will correctly reveal the top left 10 pixels of my content
(because mask.png is just a black image). However I want to animate the
mask to reveal the rest of the content:
[UIView animateWithDuration:3.0
animations:^{
mask.frame = self.content.bounds;
}
completion:^(BOOL finished){
}];
The problem is that there's no animation. The entire content gets
displayed immediately. Why does this happen, and how can I animate the
mask so that the content is revealed from the upper left?
how to wark with flask wtforms
how to wark with flask wtforms
You've gone incognito. Pages you view in this window won't appear in your
browser history or search history, and they won't leave other traces, like
cookies, on your computer after you close all open incognito windows. Any
files you download or bookmarks you create will be preserved, however.
Going incognito doesn't affect the behavior of other people, servers, or
software. Be wary of: Websites that collect or share information about you
Internet service providers or employers that track the pages you visit
Malicious software that tracks your keystrokes in exchange for free
smileys Surveillance by secret agents People standing behind you
You've gone incognito. Pages you view in this window won't appear in your
browser history or search history, and they won't leave other traces, like
cookies, on your computer after you close all open incognito windows. Any
files you download or bookmarks you create will be preserved, however.
Going incognito doesn't affect the behavior of other people, servers, or
software. Be wary of: Websites that collect or share information about you
Internet service providers or employers that track the pages you visit
Malicious software that tracks your keystrokes in exchange for free
smileys Surveillance by secret agents People standing behind you
How to Write Linq for C# ; Differences in Linq Queries
How to Write Linq for C# ; Differences in Linq Queries
If
from lang in Languages
from title in lang.Titles
where lang.name == "Arabic" && title.Type=="Movie"
Select new {title.Name, title.ReleaseYear}
is the same as
Languages
.Where(l=>l.Name == "Arabic")
.SelectMany(l=>l.Titles)
.Where(t=>t.Type=="Movie")
.Select(t=>new{
t.Name, t.ReleaseYear
})
Is there any difference in the 2 ( Query results are same, i mean backend )
Can you choose either or and consider the rest just "Preference"? - or is
one more versitile?
If
from lang in Languages
from title in lang.Titles
where lang.name == "Arabic" && title.Type=="Movie"
Select new {title.Name, title.ReleaseYear}
is the same as
Languages
.Where(l=>l.Name == "Arabic")
.SelectMany(l=>l.Titles)
.Where(t=>t.Type=="Movie")
.Select(t=>new{
t.Name, t.ReleaseYear
})
Is there any difference in the 2 ( Query results are same, i mean backend )
Can you choose either or and consider the rest just "Preference"? - or is
one more versitile?
video call not going from polycom's end terminal(Lifesize team 220)!
video call not going from polycom's end terminal(Lifesize team 220)!
We are using polycom video conferencing solution with RMX 2000 as
multiparty confrlerencing unit, DMA 4000 as gatekeeper to register devices
and also act as SIP proxy. RPAD acts for firewall traversal. Except RPAD
all other servers are kept in MZ. Rpad is in DMZ. The end terminal used is
of Lifesize Team 220. Now the situation is I am able to make call(using
H.323) from internet to the end terminal but not the reverse, that is from
end terminal to devices kept in internet. As per the network guy the
packets have not been initiated at all from the end terminal. So probably
its some configuration issue of the rpad or dma or rmx. Need some help in
this. What could be the possible issue/solution?
We are using polycom video conferencing solution with RMX 2000 as
multiparty confrlerencing unit, DMA 4000 as gatekeeper to register devices
and also act as SIP proxy. RPAD acts for firewall traversal. Except RPAD
all other servers are kept in MZ. Rpad is in DMZ. The end terminal used is
of Lifesize Team 220. Now the situation is I am able to make call(using
H.323) from internet to the end terminal but not the reverse, that is from
end terminal to devices kept in internet. As per the network guy the
packets have not been initiated at all from the end terminal. So probably
its some configuration issue of the rpad or dma or rmx. Need some help in
this. What could be the possible issue/solution?
Wednesday, 21 August 2013
Process.Start opens multiple instances
Process.Start opens multiple instances
I have the following code:
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
+ "\\Internet Explorer\\iexplore.exe", "http:\\\\someurl.com");
It runs fine, but opens two instances of IE (Needless to say, I'm
expecting one). Is there something obvious I'm missing here, or is it a
more detailed issue? I'm using Visual C# 2010 Express if that matters, and
.NET 4 Client Profile.
I have the following code:
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
+ "\\Internet Explorer\\iexplore.exe", "http:\\\\someurl.com");
It runs fine, but opens two instances of IE (Needless to say, I'm
expecting one). Is there something obvious I'm missing here, or is it a
more detailed issue? I'm using Visual C# 2010 Express if that matters, and
.NET 4 Client Profile.
Adding a Third column of data in Mathematica
Adding a Third column of data in Mathematica
I have a very large table of data something like:
lista = {{2,8},{3,4},{5,2}..}
I would like to add x to every element so it would be
lista ={{x,2,8},{x,3,4},{x,5,2}.....}
This seems to me like it should be rather trivial but I have not been able
to find a solution.
I would appreciate any help, Ben
I have a very large table of data something like:
lista = {{2,8},{3,4},{5,2}..}
I would like to add x to every element so it would be
lista ={{x,2,8},{x,3,4},{x,5,2}.....}
This seems to me like it should be rather trivial but I have not been able
to find a solution.
I would appreciate any help, Ben
Subscribe to:
Posts (Atom)