Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Koordinatenkreuz hilfe?

Empfohlene Antworten

Veröffentlicht

Hallo Leute,

bin hier relativ neu und habe mal eine Frage an euch.

Ich bin derzeit noch in der Ausbildung zum Fachinformatiker Fachrichtung Anwendungsentwicklung und habe eine kleine Aufgabe innerhalb des Betriebes bekommen.

Nun bin ich noch relativ frisch dabei (PHP, etc) und finde den richtigen Algorithmus nicht.

Vielleicht kann mir ja jemand helfen :)


Aufgabenstellung:


Erschaffe eine Karte (php) mit 8x8 quadratischen Feldern. Die Felder sollen über eine Buchstaben-Zahl Kombination ansprechbar sein. (Bis hierhin easy)


Berechne nun Diagonal die Entfernung vom Mittelpunkt von Planquadrat C3 zu F7.

Generalisiere die Methode, sodass du beliebige Felder nutzen kannst.


Nächster Schritt:

Die Bewegungen über Felder können nur an Kanten erfolgen. Diagonales ziehen ist daher nicht möglich. Finde einen Algorithmus, der einen Weg von B2 zu D3 findet. Generalisiere die Formel.

Ich erwarte keine kompletten Lösungen von euch :P. Nur ein wenig Hilfestellung wäre nett :D. Möchte ja etwas dabei lernen.

Mein derzeitige Code:


class map {

function calc($from, $to, $dia=null) {
if($dia == true) {
//Diagonal
echo "true";
}elseif($dia == false) {
//Nicht Diagonal
echo "false";
}
}

function x_axis() {
$data = array(
"1" => "",
"2" => "",
"3" => "",
"4" => "",
"5" => "",
"6" => "",
"7" => "",
"8" => ""
);
return $data;
}

function y_axis() {
$data = array(
"A" => "",
"B" => "",
"C" => "",
"D" => "",
"E" => "",
"F" => "",
"G" => "",
"H" => ""
);
return $data;
}

function view() {
$datax = $this->x_axis();
$datay = $this->y_axis();

echo "<table style='border: 1px solid #fff; font-size: 40px; margin: 0 auto;' cellspacing='0'>";
foreach($datax as $keyx => $x) {
echo "<tr style='border: 1px solid #fff;'>";
foreach($datay as $keyy => $y) {
echo "<td style='border: 1px solid #fff;'>".$keyy.$keyx."</td>";
}
echo "</tr>";
}
echo "</table>";
}
}

$mapClass = new map;
$mapClass->view();
?>

<table>
<form method="POST" action="">
<tr><td>von:</td><td><input type="text" name="from" placeholder="From"></td></tr>
<tr><td>zu:</td><td><input type="text" name="to" placeholder="To"></td></tr>
<tr><td>Diagonales ziehen:</td><td>Ja<input type="radio" name="dia" value="1">Nein<input type="radio" name="dia" value="0" checked></td></tr>
<tr><td></td><td><input type="submit" value="Berechnen" name="calc"></td></tr>
</form>
</table>

<?php
if(isset($_POST['calc'])) {
$mapClass->calc($_POST['from'], $_POST['to'], $_POST['dia']);
}
?>
[/PHP]

Stecke also bei dem Algo für die Berechnung fest :confused:. Denke die Richtung ,,Satz des Pythagoras" wäre da richtig oder...

Hi socressor,

der Satz des Pythagoras geht genau in die richtig Richtung. Ich geb dir mal folgenden Hinweis, damit solltest du dann Aufgabenteil 2 und 3 lösen ;)

(x1/y1) nach (x2/y2)

(x2-x1)^2 + (y2-y1)^2 = z^2

LG

  • Autor

Danke abermals, aber ich meine programmatisch :) (PHP)

Mein derzeitiger Stand:


<html>
<head>
<title>Möp-Karte</title>
<style type="text/css">
body {
background: #000;
color: #fff;
}
</style>
</head>
<body>
<div align="center">
<h1>Möp-Karte</h1>

<?php

class map {

function calc($from, $to) {
$numeric=array($from => '', $to => '');
$letters=array($from => '', $to => '');

$splitter = str_split($from);
$splitter2 = str_split($to);

foreach($splitter as $fv){
if(is_numeric($fv)) {
$numeric[$from]=$numeric[$from].$fv;
}else{
$letters[$from]=$letters[$from].$fv;
}
}

foreach($splitter2 as $tv){
if(is_numeric($tv)) {
$numeric[$to]=$numeric[$to].$tv;
}else{
$letters[$to]=$letters[$to].$tv;
}
}


// var_dump($numeric);
// var_dump($letters);

//$this->view($numeric,$letters);
//$this->view($from,$to);

return array($numeric, $letters);
}

function x_axis($m=null, $n=null) {
$data = array(
"1" => "",
"2" => "",
"3" => "",
"4" => "",
"5" => "",
"6" => "",
"7" => "",
"8" => ""
);


if($m != null && $n != null) {
$all = $this->calc($m, $n);
//var_dump($all);

foreach($all[0] as $signed) {
if(stristr($m,$signed)) {
$data[$signed] = $m;
}

if(stristr($n,$signed)) {
$data[$signed] = $n;
}

}
}

return $data;
}

function y_axis($m=null, $n=null) {
$data = array(
"A" => "",
"B" => "",
"C" => "",
"D" => "",
"E" => "",
"F" => "",
"G" => "",
"H" => ""
);

if($m != null && $n != null) {
$all = $this->calc($m, $n);
//var_dump($all);

foreach($all[1] as $signed) {
if(stristr($m,$signed)) {
$data[$signed] = $m;
}

if(stristr($n,$signed)) {
$data[$signed] = $n;
}
}
}

return $data;
}

function view($from=null, $to=null) {
$datax = $this->x_axis($from, $to);
$datay = $this->y_axis($from, $to);

//var_dump($datax);

echo "<table style='border: 1px solid #fff; font-size: 40px; margin: 0 auto;' cellspacing='0'>";
foreach($datax as $keyx => $x) {
echo "<tr style='border: 1px solid #fff;'>";
$datax[$keyx]="";
foreach($datay as $keyy => $y) {
if($y == $keyy.$keyx) {
echo "<td style='border: 1px solid red;'>".$keyy.$keyx."</td>";
} else {
echo "<td style='border: 1px solid #fff;'>".$keyy.$keyx."</td>";
}
}



echo "</tr>";
}
echo "</table>";
}
}

$mapClass = new map;
?>

<table>
<form method="POST" action="">
<tr><td>von:</td><td><input type="text" name="from" placeholder="From"></td></tr>
<tr><td>zu:</td><td><input type="text" name="to" placeholder="To"></td></tr>
<tr><td></td><td><input type="submit" value="Berechnen" name="calc"></td></tr>
</form>
</table>

<?php
if(isset($_POST['calc'])) {
$mapClass->view($_POST['from'], $_POST['to']);
}else{
$mapClass->view();
}
?>
</div>
</body>
</html>

[/PHP]

Das sieht so aus und makiert derzeit Start und Ziel.

post-94055-14430449821552_thumb.png

Bearbeitet von socressor
Neuster Stand

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.