etc
Check-in [c28e774f80]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:added va_list constructor, random tiles sqrt(max) etc
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:c28e774f80dc75b2207d65b95359f6350cd2548c
User & Date: alzwded 2014-04-13 11:42:24
Context
2014-04-13
11:42
added va_list constructor, random tiles sqrt(max) etc Leaf check-in: c28e774f80 user: alzwded tags: trunk
09:52
explicit return type check-in: dad69da7de user: alzwded tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to t2048/2048.cpp.

2
3
4
5
6
7
8

9
10
11
12
13
14
15
..
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <list>
#include <cstdarg>
#include <cstdio>
#include <algorithm>
#include <set>
#include <cstring>
#include <ctime>

#include "header.h"
#include "pack.hxx"

cell_t board[16] = {
    1, 0, 1, 2,
    1, 1, 1, 0,
    0, 0, 1, 0,
................................................................................
    static auto n = time(NULL);
    n = n * 3913 + 23;

    while(cells.size()) {
        auto i = cells.begin();
        std::advance(i, n % cells.size());
        if(!board[*i]) { board[*i] = maxi; break; }
        else { maxi = std::max(maxi, (cell_t)(board[*i] / 2)); }
        cells.erase(i);
    }
}

int main(int argc, char* argv[])
{
    memset(board, 0, 16); // TODO uncomment after actual game is implemented







>







 







|







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <list>
#include <cstdarg>
#include <cstdio>
#include <algorithm>
#include <set>
#include <cstring>
#include <ctime>
#include <cmath>
#include "header.h"
#include "pack.hxx"

cell_t board[16] = {
    1, 0, 1, 2,
    1, 1, 1, 0,
    0, 0, 1, 0,
................................................................................
    static auto n = time(NULL);
    n = n * 3913 + 23;

    while(cells.size()) {
        auto i = cells.begin();
        std::advance(i, n % cells.size());
        if(!board[*i]) { board[*i] = maxi; break; }
        else { maxi = std::max(maxi, (cell_t)(sqrtf((float)board[*i]))); }
        cells.erase(i);
    }
}

int main(int argc, char* argv[])
{
    memset(board, 0, 16); // TODO uncomment after actual game is implemented

Changes to t2048/Makefile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
..
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
all: a.out 2048-cleaned.cpp

a.out: 2048.o display.o pack.o
	g++ -g 2048.o pack.o display.o -lSDL -lSDL_ttf

2048.exe: 2048.obj display.obj pack.obj
	i686-w64-mingw32-g++ -static-libgcc -static-libstdc++ -o 2048.exe 2048.obj pack.obj display.obj -Lvendor/SDL-1.2.15/bin -Lvendor/SDL_ttf-2.0.11/lib/x86 -lSDL -lSDL_ttf
	cp vendor/SDL-1.2.15/bin/SDL.dll .
	cp vendor/SDL_ttf-2.0.11/lib/x86/SDL_ttf.dll .
	cp vendor/SDL_ttf-2.0.11/lib/x86/libfreetype-6.dll .
	cp vendor/SDL_ttf-2.0.11/lib/x86/zlib1.dll .

2048.obj: 2048.cpp
	i686-w64-mingw32-g++ --std=gnu++0x -g -o 2048.obj -c 2048.cpp
................................................................................
display.o: display.c
	gcc -g --std=gnu99 -c display.c

2048.o: 2048.cpp
	g++ -g --std=gnu++11 -c 2048.cpp -o 2048.o

pack.o: pack.cpp
	g++ -g --std=gnu++11 -c pack.cpp -o pack.o

2048-cleaned.cpp: 2048.cpp
	sed 2048.cpp -e '/TALK/d' > 2048-cleaned.cpp

test.out: pack.cpp
	g++ -g --std=gnu++11 -DTEST_PACK -o test.out pack.cpp
	./run-tests.csh

clean:
	rm -f a.out 2048-cleaned.cpp *.o 2048.exe *.obj *.dll *.out



|


|







 







|





|




1
2
3
4
5
6
7
8
9
10
11
12
13
14
..
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
all: a.out 2048-cleaned.cpp

a.out: 2048.o display.o pack.o
	g++ -g 2048.o pack.o display.o -lSDL -lSDL_ttf -lm

2048.exe: 2048.obj display.obj pack.obj
	i686-w64-mingw32-g++ -static-libgcc -static-libstdc++ -o 2048.exe 2048.obj pack.obj display.obj -Lvendor/SDL-1.2.15/bin -Lvendor/SDL_ttf-2.0.11/lib/x86 -lSDL -lSDL_ttf -lm
	cp vendor/SDL-1.2.15/bin/SDL.dll .
	cp vendor/SDL_ttf-2.0.11/lib/x86/SDL_ttf.dll .
	cp vendor/SDL_ttf-2.0.11/lib/x86/libfreetype-6.dll .
	cp vendor/SDL_ttf-2.0.11/lib/x86/zlib1.dll .

2048.obj: 2048.cpp
	i686-w64-mingw32-g++ --std=gnu++0x -g -o 2048.obj -c 2048.cpp
................................................................................
display.o: display.c
	gcc -g --std=gnu99 -c display.c

2048.o: 2048.cpp
	g++ -g --std=gnu++11 -c 2048.cpp -o 2048.o

pack.o: pack.cpp
	g++ -g --std=gnu++11 -c -Wall -pedantic pack.cpp -o pack.o

2048-cleaned.cpp: 2048.cpp
	sed 2048.cpp -e '/TALK/d' > 2048-cleaned.cpp

test.out: pack.cpp
	g++ -g --std=gnu++11 -DTEST_PACK -Wall -pedantic -o test.out pack.cpp -lm
	./run-tests.csh

clean:
	rm -f a.out 2048-cleaned.cpp *.o 2048.exe *.obj *.dll *.out

Changes to t2048/pack.cpp.

48
49
50
51
52
53
54








55
56
57
58
59
60
61
62
63
64




65
66
67
68
69
70
71
            cells.erase(next);
            ++cell;
        } else { // default, move to next cell
            ++cell;
        }
    }
}









Pack::Pack(cell_t* first, ...)
{
    va_list p;
    va_start(p, first);
    for(cell_t* i = first; i; i = va_arg(p, cell_t*)) {
        pointers_.push_back(i);
    }
    va_end(p);
}





Pack::Pack(Builder const& bld)
{
    std::copy(bld.begin(), bld.end(), std::inserter(pointers_, pointers_.begin()));
}

// shift cells left-to-right relative to the order the cells were







>
>
>
>
>
>
>
>





|
|
|
<
|
>
>
>
>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
79
80
81
82
            cells.erase(next);
            ++cell;
        } else { // default, move to next cell
            ++cell;
        }
    }
}

template<typename T>
static void initFromVAList(T& pointers_, cell_t* first, va_list p)
{
    for(cell_t* i = first; i; i = va_arg(p, cell_t*)) {
        pointers_.push_back(i);
    }
}

Pack::Pack(cell_t* first, ...)
{
    va_list p;
    va_start(p, first);
    initFromVAList(pointers_, first, p);
    va_end(p);
}


Pack::Pack(cell_t* first, va_list p)
{
    initFromVAList(pointers_, first, p);
}

Pack::Pack(Builder const& bld)
{
    std::copy(bld.begin(), bld.end(), std::inserter(pointers_, pointers_.begin()));
}

// shift cells left-to-right relative to the order the cells were

Changes to t2048/pack.hxx.

10
11
12
13
14
15
16


17
18
19
20
21
22
23
24
25
    // pointers to the actual cells that will be modified
    std::deque<cell_t*> pointers_;

public:
    typedef std::deque<cell_t*> Builder;

    Pack(cell_t* first, ...);



    Pack(Builder const& bld);

    // shift cells left-to-right relative to the order the cells were
    //     passed into the constructor
    int shift();
};

#endif







>
>









10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    // pointers to the actual cells that will be modified
    std::deque<cell_t*> pointers_;

public:
    typedef std::deque<cell_t*> Builder;

    Pack(cell_t* first, ...);

    Pack(cell_t* first, va_list);

    Pack(Builder const& bld);

    // shift cells left-to-right relative to the order the cells were
    //     passed into the constructor
    int shift();
};

#endif