Name: Anonymous 2011-10-06 9:06
Any code you work with right now, and we'll criticize it(or not).
sub addr-parse( Str $str, :$cidr ) {
my @chunks = $str.comb: /\d+/;
my $mask = @chunks[4] // 0;
my $base = [+] @chunks[^4] Z+< 24, 16, 8, 0;
return ( $base, $mask ) if $cidr;
return $base;
}
sub cidr-str( Int $base, Int $mask ) {
my $str = (
for 24, 16, 8, 0 -> $s { ( $base +> $s ) +& 0xff; }
).join('.') ~ '/' ~ $mask;
return $str;
}
Option Explicit
const w = 3
const h = 3
const tyhja = "_"
redim TheGame(w,h)
dim fun
dim i, j
dim inp, x, y
dim view
dim merkki
dim winner
dim random_ok
view = ""
winner = "0"
fun = True
For i = 0 To w -1
For j = 0 To h-1
TheGame(i,j) = tyhja
Next
Next
Randomize
msgbox "Super X0 !!!!!!!!!!!!!!!!!!111111oneoneelevenone" & vbCr & vbCr & "Paina OK, tampio"
Do While fun
view = ""
For i = 0 To h-1
For j = 0 To w-1
merkki = TheGame(j,i)
view = view & merkki
if merkki <> tyhja Then
If i <> 0 and i <> h-1 Then
if TheGame(j, i-1) = merkki and TheGame(j, i+1) = merkki Then
winner = merkki
fun = False
End If
End If
If j <> 0 and j <> w-1 Then
if TheGame(j-1, i) = merkki and TheGame(j+1, i) = merkki Then
winner = merkki
fun = False
End If
End If
If j <> 0 and i <> 0 and i <> h-1 and j <> w-1 Then
If (TheGame(j-1, i-1) = merkki and TheGame(j+1, i+1) = merkki) _
Or (TheGame(j+1, i-1) = merkki and TheGame(j-1, i+1) = merkki) Then
winner = merkki
fun = False
End If
End If
end if
Next
view = view & vbCr
Next
if fun then
inp = InputBox(view)
x = CInt(mid(inp, 1, 1)) - 1
y = CInt(mid(inp, 2, 1)) - 1
if TheGame(x,y) = tyhja then
TheGame(x,y) = "X"
end If
random_ok = False
do while not random_ok
x = w * Rnd
y = h * Rnd
if TheGame(x, y) <> "0" Then
TheGame(x,y) = "0"
random_ok = True
End If
loop
end if
Loop
MsgBox winner & " voitti..."
#ifndef VEC2_H_INCLUDED_
#define VEC2_H_INCLUDED_
#include <cmath>
/**
* Represents 2D vector.
*/
class Vec2
{
public:
float x, y;
/** Construct vector with given values */
Vec2(float _x, float _y) : x(_x), y(_y) {}
/** Create uninitialized vector */
Vec2(){}
/** Construct scaled copy */
Vec2(const Vec2& v, float scale_ratio) {
*this = v;
scale(scale_ratio);
}
Vec2& operator += (const Vec2& v) {
x += v.x;
y += v.y;
return *this;
}
Vec2& operator -= (const Vec2& v) {
x -= v.x;
y -= v.y;
return *this;
}
Vec2 operator + (const Vec2& v) const {
return Vec2(x+v.x, y+v.y);
}
Vec2 operator - (const Vec2& v) const {
return Vec2(x-v.x, y-v.y);
}
/** multiply with scalar */
void scale(float m) {
x *= m;
y *= m;
}
/** Dot product */
float dot(const Vec2& v) const {
return x * v.x + y * v.y;
}
/** Cross product */
Vec2 cross(const Vec2& v) const {
return Vec2(y - v.y, x - v.y);
}
float length() const {
return std::sqrt(length2());
}
/** Square of length */
float length2() const {
return x*x + y*y;
}
/** Distance to other vector */
float distance(const Vec2& v) const {
return std::sqrt(distance2(v));
}
/** Distance to other vector squared */
float distance2(const Vec2& v) const {
float dx = x - v.x;
float dy = y - v.y;
return dx*dx + dy*dy;
}
/** Normalize vector. The length after normalization is 1 */
void normalize() {
scale(1 / length());
}
/** set new value */
void set(float _x, float _y) {
x = _x;
y = _y;
}
/** Rotate vector by angle radians */
void rotate(float angle) {
float len = length();
angle += atan2(y, x);
x = cos(angle) * len;
y = sin(angle) * len;
}
/** Create vector projection: u projected to *this */
Vec2 projection(const Vec2& u) const {
Vec2 p = *this;
float len = length();
p.scale(this->dot(u) / (len * len));
return p;
}
};
#endif