I'm creating an application that allow the user to draw out a floor plan. It gives them a 12 x 8 grid and lets them click up to 50 sqaures. It stops them when they get to 50 but they can click on an already selected sqaure to turn it blank and then choose another.
What I need to be able to do is check the plan. They can't have any gaps in it. All squares have the accesable from all other square on only in the four main directions (no diagonals).
Is there some kind of function that could image a man standing in square one and making sure he can visit all the other squares.
I'm willing to use php or JavaScript if required. Is there anything already around that will do that, or would somebody be able to assist me.
There code for creating the floor plan is below. - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
-
<head>
-
<title>Plan</title>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
-
<script type="text/javascript">
-
<!--
-
var count=0;
-
-
function plan(id)
-
{
-
var obj = document.getElementById(id);
-
-
if(obj.style.backgroundColor == "rgb(0, 0, 0)")
-
{
-
if(count <= 49)
-
{
-
count++;
-
}
-
else
-
{
-
alert('You can have a maximum of 50');
-
count++;
-
}
-
}
-
else if(obj.style.backgroundColor == "rgb(255, 0, 0)")
-
{
-
count--;
-
}
-
if(count <= 50)
-
{
-
obj.style.backgroundColor = (obj.style.backgroundColor == "rgb(0, 0, 0)") ? "#ff0000" : "#000000";
-
obj.style.color = (obj.style.backgroundColor == "rgb(0, 0, 0)") ? "#000000" : "#ffffff";
-
}
-
if (count>50)
-
{
-
count--;
-
}
-
}
-
-
function number()
-
{
-
var room_number=0;
-
col=0;
-
row="a";
-
for (var i=1; i<97; i++)
-
{
-
col++;
-
if (i<97)
-
{
-
row="h";
-
}
-
if (i<85)
-
{
-
row="g";
-
}
-
if (i<73)
-
{
-
row="f";
-
}
-
if (i<61)
-
{
-
row="e";
-
}
-
if (i<49)
-
{
-
row="d";
-
}
-
if (i<37)
-
{
-
row="c";
-
}
-
if (i<25)
-
{
-
row="b";
-
}
-
if (i<13)
-
{
-
row="a";
-
}
-
-
if (col>12)
-
{
-
col=1;
-
}
-
var room = document.getElementById(row+col);
-
if (room.style.backgroundColor == "rgb(255, 0, 0)")
-
{
-
room_number++;
-
room.textContent=room_number;
-
}
-
else
-
{
-
room.textContent="";
-
}
-
}
-
}
-
//-->
-
</script>
-
</head>
-
-
<body style="background-color: #000000; width: 386px; margin: 10px auto 0;">
-
<?php
-
$l=0;
-
$j=0;
-
-
for ($i=0; $i<96; $i++)
-
{
-
$l++;
-
$j++;
-
if ($j<97)
-
{
-
$letter=h;
-
}
-
if ($j<85)
-
{
-
$letter=g;
-
}
-
if ($j<73)
-
{
-
$letter=f;
-
}
-
if ($j<61)
-
{
-
$letter=e;
-
}
-
if ($j<49)
-
{
-
$letter=d;
-
}
-
if ($j<37)
-
{
-
$letter=c;
-
}
-
if ($j<25)
-
{
-
$letter=b;
-
}
-
if ($j<13)
-
{
-
$letter=a;
-
}
-
-
if ($l>12)
-
{
-
$l=1;
-
}
-
$border="2px 0 0 2px";
-
if ($l==12)
-
{
-
$border="2px 2px 0 2px";
-
}
-
if ($j>84)
-
{
-
$border="2px 0 2px 2px";
-
}
-
if ($j==96)
-
{
-
$border="2px 2px 2px 2px";
-
}
-
?>
-
<div style="width: 30px; height: 30px; line-height: 30px; border-style: solid; border-color: #ffffff; border-width: <?=$border;?>; float: left; background-color: #000000; color: #ffffff; text-align: center; vertical-align: middle; font-weight: 700;" id="<?=$letter, $l;?>" onclick="plan('<?=$letter, $l;?>');"> </div>
-
<?php
-
}
-
?>
-
<input type="button" value="Done" onclick="number();"/>
-
</body>
-
</html>
5 1050
Loop through every box and if it is an "active box" check the north, south, east, and west, boxes for at least one active box.
I thought about that but found that if there could you have two groups of four boxes not connected. Someone did this once and I'm not sure how but this was 30 years ago on the computers of that day!
In that case, you want to find the first "active" box and use a recursive algorithm to traverse all the connected boxes. Use an array to keep track of the traversed boxes. Then compare the traversal array to the original boxes to see if any "active" boxes have not been traversed.
This way, only one group can ever be traversed.
That's the idea. I was just wondering if someone could start me off because I'm not quite what way to go around it.
It's not quite as simple on some plans. Would it help if included a plan that does work that I've used but would be very tricky to validate?
It wouldn't hurt to have an example.
In pseudo-code, the traversal would look like this: -
function isValid() {
-
for each box
-
if box is active
-
traverse box
-
exit for
-
-
for each box
-
if box is active and not traversed
-
return fail
-
-
return pass
-
}
-
-
function traverse(box) {
-
mark box as traversed in traversal array
-
-
if north box is active and not traversed
-
traverse north box
-
-
if east box is active and not traversed
-
traverse east box
-
-
if south box is active and not traversed
-
traverse south box
-
-
if west box is active and not traversed
-
traverse west box
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jay |
last post by:
Hi !
I am a beginner in PHP. Does anybody know how to check if an URL is
alive or dead in PHP (not exist or server down...or whatever ) ?
Any help would be appreciated !
Thanks !
Jay
|
by: Bryan Parkoff |
last post by:
Do C/C++ Compiler allow function to contain more than 8 parameters? I
checked MS Visual C++ 6.0 that it can only limit 8 parameters, but
most C/C++ Compiler can limit maximum 256 parameters. Can...
|
by: vncntj |
last post by:
i want to enable one listbox and disable the other depending on if i
check winter_gala (checkbox)
here is my code.
<script type="text/javascript">
function check()
{
if...
|
by: Dknight |
last post by:
Hi, all!
I have a problem, how can I check a form data before sending it to
server. I have the example below, but first data is sent to server, but
after JavaScript checks the data :(
I need...
|
by: padew |
last post by:
<form method="post" name="formWin" onSubmit="check();">
this work
only if I send the form's datas directly with <input type=submit ...>
if I use document.formWin.submit(); for to send the...
|
by: ext237 |
last post by:
hello.
I'm trying to halt a function's execution while waiting for user
interaction.
For example, I have a function called getUserValue() that pops up a hidden
div containing several buttons....
|
by: Dave Siegel |
last post by:
Hey,
Is it possible to have the webbrowser give me a msgbox of the javascript execution every time javascript has been executed?
If yes,
How? Because i'm oblivious on how to get it.
|
by: shivendravikramsingh |
last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
|
by: maheswaran |
last post by:
hi all,
I have doubt in class_exist funxtion. I know its use to Tests whether a class is defined or not. But i want to know how its work. Is this function check any specific DB or any definition...
|
by: amit yogi |
last post by:
hi , i am making a form of user registratin and using server side validation. but function is not working on click. please suggest...
<html>
<head>
<script language="javascript">
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |