Designing solutions through programming - May 25 Lesson Notes

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff) What are we going to learn today?

<?php
// This progam creates and prints a simple grid
// initialize the array
\$grid = [];

// populate the array:

for(\$i=0;\$i<300;\$i++){

\$new_number = rand(1,3);

if(\$new_number == 2 || \$new_number ==3){
\$new_number = rand(1,3);
}

\$grid[] = \$new_number;

}

// print the array so it looks like a grid

echo "<!doctype html>";
echo "<html>";
echo "<meta charset=\"utf-8\"/>";
echo "<style>
body { font-family: \"courier\"; }</style>";
\$count = 0;
\$row_length = 20;

\$player_location = 50;
\$grid[\$player_location] = 4;

foreach(\$grid as \$i) {
\$count = \$count + 1;

if(\$i==1){
echo " .  ";
} elseif(\$i==2) {
echo "<font color=\"green\"> \u{1F332} </font>";
} elseif(\$i==3) {
echo "<font color=\"red\"> \u{26F0} </font>";
} elseif(\$i == 4) {
echo " \u{1F464} ";
}

if(\$count == \$row_length) {
echo "<br />";
\$count = 0;
}
}

\$count_terrain_features = array_count_values(\$grid);
echo "<br /><hr /><br />";
echo "There are \$count_terrain_features open terrain tiles on this map<br />";
echo "There are \$count_terrain_features trees tiles on this map.<br />";
echo "There are \$count_terrain_features mountain tiles on this map<br />";
echo "<br /><hr /><br />";
// print_r(\$count_terrain_features);

// we now just draw the numbers to help map designers understand the numbers :-)

\$count = 0;
foreach(\$grid as \$i){
\$count= \$count+1;
echo " \$i ";
if(\$count == \$row_length){
echo "<br />";
\$count =0;
}

}
echo "<br /><hr /><br />";
\$count =0;
\$position = 0;
foreach(\$grid as \$i){
\$count++;
\$position ++;
if(\$count == \$row_length) {
echo "<br />";
\$count = 0;
}

}

?>

1. None How am I being assessed today?

1. You get a formative assessment today :-) As a computer scientist, you have:

• Confidence in dealing with complexity
• Persistence in working with difficult problems
• Tolerance for ambiguity
• The ability to deal with open-ended problems
• The ability to communicate and work with others to achieve a common goal or solution