all stats

JJRubes's stats

guessed the most

namecorrect guessesgames togetherratio
seshoumara560.833
luatic260.333
olus2000280.250
soup girl150.200
kimapr150.200
moshikoi170.143
LyricLy1100.100
taswelll050.000
razetime060.000
Olivia060.000

were guessed the most by

namecorrect guessesgames togetherratio
kimapr250.400
taswelll250.400
LyricLy4100.400
soup girl140.250
olus2000180.125
moshikoi060.000
seshoumara060.000
luatic060.000
razetime060.000
Olivia060.000

entries

round #66

submitted at
0 likes

guesses
comments 0

post a comment


cg65.hs ASCII text, with CRLF line terminators
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def next_gijswijt(l):
    max_count = 1
    for i in range(len(l)//2):
        i += 1
        pattern = l[-i:]
        count = 1
        while pattern == l[-(count+1)*i:-count*i] and count*i < len(l):
            count += 1
        max_count = max(max_count, count)
    return max_count

def gijswijt(n):
    l = [1]
    for i in range(n - 1):
        l.append(next_gijswijt(l))
    return l

if __name__ == "__main__":
    print(gijswijt(int(input())))

round #57

submitted at
0 likes

guesses
comments 0

post a comment


brain data
cg57.c ASCII text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#include<stdint.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

char* magic = "x_//xo_x__ox//x_ox/x/o/ox_xx/xo_x_x_xxxx_/x_o//xoxx_//x_xx_o/x_o_oo_o__/__ox_ox/_/__x/ox/_o/xox_/_/o_xo_/x_/x_xx/xxoo_/__ox/x_xo__/x/__o_x/xoo_/oo_//x_oo/o/oxxxoo/xxxxxo__xx/__x_x/x//xx/x//_x_/o__xoxo/o/ox_/";

typedef struct node
{
    uint32_t stateSeed;
    uint32_t outputSeed;
    uint32_t nodeSeed;
    uint8_t transitionList[64];
} node;

uint32_t pringles(uint32_t state)
{
	state ^= state << 13;
	state ^= state >> 17;
	state ^= state << 5;
	return state;
}

enum INPUT
{
    BLANK,
    BAR,
    X,
    O,
    END,
    INVALID
};

typedef struct
{
    // 8 bits
    uint8_t internal;
    // 6 bits
    uint8_t output;
    // 6 bits
    uint8_t next;
} nextState;

node* loadBrain(char* fileName)
{
    FILE *f = fopen(fileName, "rb");
    if (!f)
        return NULL;
    node *brain = (node*)malloc(256 * sizeof(node));
    if (fread(brain, sizeof(node), 256, f) != 256)
    {
        free(brain);
        return NULL;
    }
    return brain;
}

nextState eat(node* current, enum INPUT in, uint8_t state)
{
    nextState s = {0};
    int vari = state + (in << 8);
    vari += vari << 16;
    s.internal = (uint8_t)((pringles(current->stateSeed + vari) >> 20) & 0xff);
    s.output = (uint8_t)((pringles(current->outputSeed + vari) >> 20) & 0x3f);
    s.next = (uint8_t)((pringles(current->nodeSeed + vari) >> 20) & 0x3f);
    s.next = current->transitionList[s.next];
    return s;
}

typedef struct
{
    size_t length;
    size_t capacity;
    uint8_t* str;
} sstr;

void append(sstr* s, uint8_t c)
{
    if (s->length >= s->capacity)
    {
        s->capacity *= 2;
        s->str = (uint8_t*)realloc(s->str, s->capacity / 4);
    }
    if (s->length % 4 == 0)
        s->str[s->length / 4] = 0;
    s->str[s->length / 4] |= c << (2 * (s->length % 4));
    s->length++;
}

enum INPUT charToInput(char c)
{
    switch(c)
    {
        case '_':
        case ' ':
            return BLANK;
        case '|':
        case '/':
            return BAR;
        case 'x':
        case 'X':
            return X;
        case 'o':
        case 'O':
            return O;
        default:
            return INVALID;
    }
}



sstr toSstr(char* str)
{
    sstr s = {0, 12, (uint8_t*)malloc(12 / 4)};
    int len = strlen(str);
    for (int i = 0; i < len; i++)
    {
        enum INPUT in = charToInput(str[i]);
        if (in == INVALID)
        {
            s.length = -1;
            return s;
        }
        append(&s, in);
    }
    return s;
}

enum INPUT get(sstr in, size_t i)
{
    if (i >= in.length)
        return END;
    return (in.str[i / 4] >> (2 * (i % 4))) & 3;
}

char* toStr(sstr s)
{
    char* str = malloc((s.length + 1) * sizeof(char));
    str[s.length] = '\0';
    for (int i = 0; i < s.length; i++)
    {
        switch (get(s, i))
        {
            case BLANK:
                str[i] = '_';
                break;
            case BAR:
                str[i] = '/';
                break;
            case X:
                str[i] = 'x';
                break;
            case O:
                str[i] = 'o';
                break;
            default:
                free(str);
                return NULL;
        }
    }
    return str;
}

int updateStr(sstr* old, uint8_t instruction)
{
    if (!instruction)
    {
        return 1;
    }
    switch (instruction & 060)
    {
        case 000:
            break;
        case 020:
            append(old, (instruction >> 2) & 3);
            append(old, instruction & 3);
            break;
        case 040:
        case 060:
            append(old, instruction & 3);
            break;
    }
    return 0;
}

sstr move(sstr in, node* brain)
{
    int i = 0;
    node* currentNode = brain;
    uint8_t state;
    sstr str = {0, 12, (uint8_t*)malloc(12 / 4)};
    nextState s = {0, 0, 0};
    int j;
    for (j = 0; j < 4096; j++)
    {
        enum INPUT c = get(in, i++);
        s = eat(currentNode, c, state);
        state = s.internal;
        currentNode = brain + s.next;
        if (updateStr(&str, s.output))
        {
            if (c != END)
                printf("truncated by halt\n");
            break;
        }
    }
    return str;
}

int main(int argc, char** argv)
{
    /** TODO train ai **/
    if(argc != 2)
    {
        printf("Usage:\n"
                "  For the game:\n"
                "    x|o| \n"
                "    -+-+-\n"
                "    o|x|x\n"
                "    -+-+-\n"
                "    x| | \n"
                "  use ./%s xo_/oxx/x__\n",
                argv[0]);
        return 1;
    }

    sstr s = toSstr(argv[1]);
    if (s.length == -1)
    {
        printf("Invalid character. Use only '_', '/', 'x', or 'o' in input.\n");
        return 1;
    }
    node* brain = loadBrain("brain");
    if (brain == NULL)
    {
        printf("Could not open brain file.\n");
        return 1;
    }
    sstr nextPosition = move(s, brain);
    char* outputString = toStr(nextPosition);
    if (strcmp(outputString, magic) == 0)
        printf("Secret: %s\n", s.str);
    printf("%s\n", outputString);
    return 0;
}

round #53

submitted at
0 likes

guesses
comments 0

post a comment


boxes.py Unicode text, UTF-8 text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
class Object:
    def __init__(self, t=None, source=None):
        self.t = t
        self.source = source
        self.connections = []
        self.section = None
        self.left_extent = None
        self.right_extent = None


class CharInfo:
    def __init__(self, char, index):
        self.char = char
        self.index = index
        self.right_obj = None
        self.down_obj = None


def connects_up(character):
    return character in "│└┘├┤┴"


def connects_left(character):
    return character in "─┐┘┤┬┴"


def connects_right(character):
    return character in "─┌└├┬┴"


def connects_down(character):
    return character in "│┌┐├┤┬"


def valid_connections(y, x, drawing):
    above = " " if y == 0 else drawing[y - 1][x]
    below = " " if y == len(drawing) - 1 else drawing[y + 1][x]
    left  = " " if x == 0 else drawing[y][x - 1]
    right = " " if x == len(drawing[y]) - 1 else drawing[y][x + 1]
    curr = drawing[y][x]
    if connects_down(above) != connects_up(curr):
        return False
    if connects_up(below) != connects_down(curr):
        return False
    if connects_right(left) != connects_left(curr):
        return False
    if connects_left(right) != connects_right(curr):
        return False
    return True


def valid_insidedness(curr, aboves):
    if curr.char == " ":
        return True
    for above in aboves:
        if above == None:
            continue
        if above.t == "line":
            continue
        if curr.right_obj == above or curr.down_obj == above:
            continue
        if above.left_extent < curr.index < above.right_extent:
            if above.t == "box":
                return False
            above.t = "line"
    return True


def valid_unification(curr, left, above):
    match curr.char:
        case "┌":
            curr.right_obj = Object()
            curr.right_obj.left_extent = curr.index
            curr.right_obj.section = "top"
            curr.down_obj = curr.right_obj
        case "─":
            curr.right_obj = left
        case "│":
            curr.down_obj = above
        case "┐":
            if left.section == "top":
                left.section = "middle"
                left.right_extent = curr.index
            else:
                if left.t == "box":
                    return False
                left.t = "line"
            curr.down_obj = left
        case "└":
            if curr.index != above.left_extent:
                if above.t == "box":
                    return False
                above.t = "line"
            above.section = "bottom"
            curr.right_obj = above
        case "┘":
            if (above.t == "box" or left.t == "box") and above != left:
                return False
            if above.t == "line" or left.t == "line" or above != left:
                above.t = "line"
                left.t = "line"
                if above == left:
                    return False
                if above in left.connections:
                    return False
                above.connections.append(left)
                left.connections.append(above)
                if above.source == None or left.source == None:
                    if above.source == None:
                        above.source = left.source
                    else:
                        left.source = above.source
                else:
                    if above.source == left.source:
                        return False
                    if above.source in left.source.connections:
                        return False
                    above.source.connections.append(left.source)
                    left.source.connections.append(above.source)
        case "├":
            if above.t == "line":
                return False
            above.t = "box"
            if curr.index == above.left_extent:
                return False
            curr.down_obj = above
            curr.right_obj = Object("line", above)
        case "┬":
            if left.t == "line":
                return False
            left.t = "box"
            if left.section == "top":
                return False
            curr.right_obj = left
            curr.down_obj = Object("line", left)
        case "┤":
            if above.t == "line":
                return False
            above.t = "box"
            if curr.index == above.right_extent:
                return False
            if left.t == "box":
                return False
            left.t = "line"
            if left.source == above:
                return False
            if left.source in above.connections:
                return False
            if left.source == None:
                left.source = above
            else:
                above.connections.append(left.source)
                left.source.connections.append(above)
            curr.down_obj = above
        case "┴":
            if left.t == "line":
                return False
            left.t = "box"
            if left.section == "bottom":
                return False
            if above.t == "box":
                return False
            above.t = "line"
            if above.source == left:
                return False
            if above.source in left.connections:
                return False
            if above.source == None:
                above.source = left
            else:
                left.connections.append(above.source)
                above.source.connections.append(left)
            curr.right_obj = left
        case " ":
            return True
        case _:
            return False
    return True


def valid_box_drawing(drawing):
    if len(drawing) == 0:
        return True
    drawing_width = len(drawing[0])
    left = None
    aboves = []
    for index, character in enumerate(drawing[0]):
        curr = CharInfo(character, index)
        if not valid_connections(0, index, drawing):
            return False
        if not valid_unification(curr, left, None):
            return False
        aboves.append(curr.down_obj)
        left = curr.right_obj
    for line_index, line in enumerate(drawing[1:]):
        if len(line) != drawing_width:
            return False
        left = None
        belows = []
        for index, character in enumerate(line):
            curr = CharInfo(character, index)
            above = aboves[index]
            if not valid_connections(line_index, index, drawing):
                return False
            if not valid_unification(curr, left, above):
                return False
            if not valid_insidedness(curr, aboves):
                return False
            belows.append(curr.down_obj)
            left = curr.right_obj
        aboves = belows
    return True
test.py Unicode text, UTF-8 text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
from boxes import valid_box_drawing

def test(drawing, expected):
    if valid_box_drawing(drawing) == expected:
        print("Passed")
    else:
        print(f"Failed: Expected {expected} for:")
        for line in drawing:
            print(line)


test([], True)
test([""], True)
test([" "], True)
test(["", ""], True)
test([" ", " "], True)
test(
    [
        "┌──────┐",
        "│      │",
        "│      │",
        "│      │",
        "└──────┘"
    ],
    True
)
test(
    [
        "┌──────────────────────────────────────────┐           ",
        "│                                          │           ",
        "│                                          │           ",
        "│                                          │           ",
        "│                                          │           ",
        "│                                          │         ┌┐",
        "│                                          │         └┘",
        "│                                          │           ",
        "│                                          │           ",
        "│                                          │           ",
        "│                                          │           ",
        "│                                          │           ",
        "└──────────────────────────────────────────┘           "
    ],
    True
)
test(
    [
        "┌──────┐┌────┐",
        "│      ││    │",
        "└──────┘└────┘"
    ],
    True
)
test(
    [
        "┌────────┐        ┌────────┐",
        "│        │        │        │",
        "│        ├────────┤        │",
        "│        │        │        │",
        "└────────┘        └────────┘"
    ],
    True
)
test(
    [
        " ┌───────┐ ",
        " │       │ ",
        "┌┴┐     ┌┴┐",
        "└─┘     └─┘"
    ],
    True
)
test(
    [
        " ┌───────┐",
        " │      ┌┘",
        "┌┴┐    ┌┴┐",
        "└─┘    └─┘"
    ],
    True
)
test(
    [
        "┌────────┐ ",
        "│ ┌─┐    │ ",
        "│ └┬┘    │ ",
        "└──┘     │ ",
        "        ┌┴┐",
        "        └─┘"
    ],
    True
)
test(
    [
        "┌─┐",
        "└┬┘",
        "┌┴┐",
        "└─┘"
    ],
    True
)
test(
    [
        "┌┐┌┐",
        "│├┤│",
        "└┘└┘"
    ],
    True
)
test(
    [
        "┌─┐┌─┐",
        "│ ├┤ │",
        "└┬┘└┬┘",
        "┌┴┐┌┴┐",
        "│ ├┤ │",
        "└─┘└─┘"
    ],
    True
)
test(
    [
        "        ┌───────┐",
        "        │       │",
        "  ┌─────┤       │",
        "  │     └───────┘",
        "┌─┴──┐           ",
        "│    │           ",
        "│    │           ",
        "└────┘           "
    ],
    True
)
test(
    [
        "┌──────┐             ",
        "└┬──┬──┘    ┌───────┐",
        " │  │       │       │",
        " │  └───────┤       │",
        " └────┐     └───┬───┘",
        "    ┌─┴──┐     ┌┘    ",
        "    │    │    ┌┘     ",
        "    │    ├┐   └────┐ ",
        "    └────┘└────────┘ "
    ],
    True
)
test(
    [
        "┌──────┐    ",
        "│      │    ",
        "│      └───┐",
        "│          │",
        "└──────────┘"
    ],
    False
)
test(
    [
        "a",
    ],
    False
)
test(
    [
        "┌",
    ],
    False
)
test(
    [
        "┌──────┬────┐",
        "│      │    │",
        "└──────┴────┘"
    ],
    False
)
test(
    [
        "     ┌────┐",
        "┌────┼────┘",
        "└────┘     "
    ],
    False
)
test(
    [
        "┌──────────────────────────────────────────┐",
        "│                                          │",
        "│                                          │",
        "│       ┌┐        ┌┐     ┌───────┐         │",
        "│       ││┌┐      ││     │┌─────┐│         │",
        "│       ││└┘┌┐    ││     ││     ││         │",
        "│       ││  └┘┌┐  ││     ││     ││         │",
        "│       ││    └┘┌┐││     ││     ││         │",
        "│       ││      └┘││     ││     ││         │",
        "│       ││        ││     │└─────┘│         │",
        "│       └┘        └┘     └───────┘         │",
        "│                                          │",
        "└──────────────────────────────────────────┘"
    ],
    False
)
test(
    [
        "┌──────┐          ┌───────",
        "│      │          │      │",
        "│                 │      │",
        "└──────┘          └──────┘",
        "                          ",
        "         ┌──────┐         ",
        "         │      │         ",
        "         │      ┤         ",
        "         └──────┘         "
    ],
    False
)
test(
    [
        "┌──────┐",
        "│      │",
        "│       ",
        "└──────┘"
    ],
    False
)
test(
    [
        "          ",
        " ┌─────── ",
        " │      │ ",
        " │      │ ",
        " └──────┘ ",
        "          "
    ],
    False
)
test(
    [
        "┌──────┐",
        "│      │",
        "│      ┤",
        "└──────┘"
    ],
    False
)
test(
    [
        "    ┌──────────────────┐    ",
        "┌───┴────┐        ┌────┴───┐",
        "│        │        │        │",
        "│        ├────────┤        │",
        "│        │        │        │",
        "└────────┘        └────────┘"
    ],
    False
)
test(
    [
        "┌────────┐        ┌────────┐",
        "│        │        │        │",
        "│        ├────────┤        │",
        "│        │        │        │",
        "└────────┤        └────────┘",
        "         │                  ",
        "         ├────────┐         ",
        "         │        │         ",
        "         │        │         ",
        "         │        │         ",
        "         └────────┘         "
    ],
    False
)
test(
    [
        "┌────────┐        ┌────────┐",
        "│        │        │        │",
        "│        ├────────┤        │",
        "│        │        │        │",
        "└────────┤        ├────────┘",
        "         │        │         ",
        "         ├────────┤         ",
        "         │        │         ",
        "         │        │         ",
        "         │        │         ",
        "         └────────┘         "
    ],
    False
)
test(
    [
        "┌┐     ┌┐     ┌┐     ┌┐  ",
        "││     ││     ││     ││  ",
        "│├──┴──┤│     │├──┐  │├─┐",
        "││     ││     ││  │  ││ │",
        "└┘     └┘     └┘  │  └┘ │",
        "                  │     │",
        "┌┐     ┌┐     ┌┐  │  ┌┐ │",
        "││     ││     ││  │  ││ │",
        "│├─────││     │├──┼──┤│ │",
        "││     ││     ││  │  ││ │",
        "└┘     └┘     └┘  │  └┘ │",
        "                  └─────┘"
    ],
    False
)
test(
    [
        "┌┐     ┌┐",
        "││     ││",
        "│├──┴──┤│",
        "││     ││",
        "└┘     └┘"
    ],
    False
)
test(
    [
        "┌┐     ┌┐",
        "││     ││",
        "│├─────││",
        "││     ││",
        "└┘     └┘"
    ],
    False
)
test(
    [
        "┌┐     ┌┐  ",
        "││     ││  ",
        "│├──┐  │├─┐",
        "││  │  ││ │",
        "└┘  │  └┘ │",
        "    │     │",
        "┌┐  │  ┌┐ │",
        "││  │  ││ │",
        "│├──┼──┤│ │",
        "││  │  ││ │",
        "└┘  │  └┘ │",
        "    └─────┘"
    ],
    False
)
test(
    [
        "┌────────┐",
        "│        │",
        "│        │",
        "│       ┌┘",
        "└───────┘ "
    ],
    False
)

round #45

submitted at
2 likes

guesses
comments 0

post a comment


dir jeu
Case.java Unicode text, UTF-8 text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package jeu;

public class Case {

    char nature;

    /**
     * Constructeur de Case
     *
     * @param nature_
     */
    Case (char nature_) {
        this.nature = nature_;
    }

    /**
     * get la nature d'une case
     *
     * @return nature de la case
     */
    public char getNature() {
        return this.nature;
    }

    /**
     * Permet de donner/changer la nature d'une case
     *
     * @param nat la nature à donner
     */
    public void setNature(char nat) {
        this.nature = nat;
    }
}
Conversion.java ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
package jeu;

public class Conversion {

    /**
     * Retourne le char d'une case en String (ex: A10 --> A)
     *
     * @param caseEnString la case en String
     * @return x le char de la case
     */
    public char getCharFromString(String caseEnString){
        char x = ' ';
        if (caseEnString.length() == 2) {
            x = caseEnString.charAt(0);
        } else if (caseEnString.length() == 3) {
            x = caseEnString.charAt(0);
        }
        return x;
    }

    /**
     * Retourne l'entier d'une case en String (ex: A10 --> 10)
     *
     * @param caseEnString la case en String
     * @return y
     */
    public int getIntFromString(String caseEnString){
        int y = 0;
        if (caseEnString.length() == 2) {
            y = Integer.parseInt(caseEnString.substring(1));
        } else if (caseEnString.length() == 3) {
            y = Integer.parseInt(caseEnString.substring(1, 3));
        }
        return y;
    }

    public void formatCoupJoues(String coord1, String coord2, String nom, String nom2){
        String indent = "              "; // 20 spaces.
        int l;

        int add1 = nom.length()/2;
        int add2 = nom2.length()/2;

        if (nom.length() == 1){
            nom = " " + nom + indent.charAt(0);
            add1 = 1;
        } else if (nom.length() == 2){
            nom += indent.charAt(0);
        }

        l = nom2.length();
        nom2 = " " + nom2;
        if (l == 1){
            nom2 += " |";
            add2 = 1;
        } else if (l == 2){
            nom2 += indent.substring(0, 2) + "|";
        } else {
            nom2 += " |";
        }

        l = coord1.length();
        coord1 = indent.substring(0, add1) + coord1 + indent.substring(0, add1);
        if(l == 2){
            coord1 += " ";
        }

        l = coord2.length();
        coord2 = indent.substring(0, add2) + coord2 + indent.substring(0, add2);
        if (l == 2){
            coord2 += " ";
        }

        System.out.println("| "+nom+" |"+nom2);
        System.out.println("|"+coord1+"|"+coord2+"|\n");
    }
}
IA.java Unicode text, UTF-8 text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package jeu;

import java.util.ArrayList;
import java.util.Random;

public class IA {

    final String name;
    private final Random random = new Random();

    /**
     * Le constructeur de la classe IA
     *
     * @param name_ le nom de l'IA
     */
    IA(String name_) {
        this.name = name_;
    }

    /**
     * Renvoie le nom de l'IA
     *
     * @return le nom de l'IA
     */
    public String getName() {
        return this.name;
    }

    /**
     * Permet à l'IA de jouer un coup choisi au hasard choisi parmi les coups possibles
     *
     * @param coupsPossibles la liste des coups possibles
     * @return un coup choisi au hasard
     */
    public Case joueUnCoupRandom(ArrayList<Case> coupsPossibles) {
        return coupsPossibles.get(random.nextInt(coupsPossibles.size()));
    }
}
Joueur.java Unicode text, UTF-8 text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
package jeu;
import java.util.ArrayList;
import java.util.List;

public class Joueur {

    String nomJoueur;
    int numJoueur;
    char natureJoueur;
    boolean isIA;
    List<String> coupJoues = new ArrayList<>();

    /**
     * Le constructeur de la classe Joueur
     *
     * @param nomJoueur le nom de joueur
     * @param nbJoueur le numéro du joueur
     * @param natureJoueur le symbole qu'utilisera le joueur
     * @param status est-ce que le joueur est une IA ou pas
     */
    Joueur(String nomJoueur, int nbJoueur, char natureJoueur, boolean status) {
        this.nomJoueur = nomJoueur;
        this.numJoueur = nbJoueur;
        this.natureJoueur = natureJoueur;
        this.isIA = status;
    }

    /**
     * Ajoute un coup aux coups joués du joueur
     *
     * @param coupJoue le coup joué
     */
    public void addCoupJoues(String coupJoue){
        this.coupJoues.add(coupJoue);
    }

    /**
     * Change le nom du joueur
     *
     * @param nomJoueur le nom à utiliser
     */
    public void setNomJoueur(String nomJoueur){
        this.nomJoueur = nomJoueur;
    }

    /**
     * Renvoie le nom du joueur
     *
     * @return le nom du joueur
     */
    public String getNomJoueur(){
        return this.nomJoueur;
    }

    /**
     * Change le numéro du joueur
     *
     * @param numJoueur le numéro à utiliser
     */
    public void setNumJoueur(int numJoueur){
        this.numJoueur = numJoueur;
    }

    /**
     * Renvoie le numéro du joueur
     *
     * @return le numéro du joueur
     */
    public int getNumJoueur(){
        return this.numJoueur;
    }

    /**
     * Renvoie la nature du joueur
     *
     * @return la nature du joueur
     */
    public char getNature() {
        return this.natureJoueur;
    }

    /**
     * Renvoie le statut du joueur
     *
     * @return le statut du joueur
     */
    public boolean getStatus() {
        return isIA;
    }

    /**
     * Change le statut du joueur
     *
     * @param status le statut à utiliser
     */
    public void setStatus(boolean status) {
        this.isIA = status;
    }

}
Main.java Unicode text, UTF-8 text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package jeu;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    static private final Scanner in = new Scanner(System.in);
    static private char x;
    static private int y;
    static private boolean boot = true;
    static private char nature = 'X';
    static private Joueur jH = new Joueur("Joueur1", 0, 'X', false);
    static private Joueur j2;
    static private IA playerIA = new IA("IA");
    static private int playersTurn = 1;

    /**
     * La fonction Main du programme
     * 
     * @param args
     */
    public static void main(String[] args) {
        UI m = new UI();
        Screen s = new Screen(bootMain()); // max 26 because the alphabet is 26 char long :)

        s.clear();
        s.display(0);

        System.out.println("* Menu *");
        while (true) {
            String input = "";
            if (playersTurn == 1) {
                input = m.userInterface(jH.nomJoueur, jH.coupJoues, s);
            } else if (playersTurn == 2){
                if (j2.isIA) {
                    input = Screen.getStringFromCase(playerIA.joueUnCoupRandom(s.getAllPossiblePlays(false)));
                } else {
                    input = m.userInterface(j2.nomJoueur, j2.coupJoues, s);
                }
            }

            try {
                if (input.length() == 2) {  //Formate l'entrée utlisateur en Char et int
                    x = input.charAt(0);
                    y = Integer.parseInt(input.substring(1));
                } else if (input.length() == 3) {
                    x = input.charAt(0);
                    y = Integer.parseInt(input.substring(1, 3));
                }
            } catch (Exception e){
                System.out.println("La valeur entrée n'est pas valable");
            }


            if (s.checkUserInput(x, y)) {
                if (playersTurn == 1) {
                    jH.addCoupJoues(input);
                    nature = jH.natureJoueur;
                    playersTurn++;
                } else if (playersTurn == 2) {
                    if (j2.isIA) {
                        System.out.println("L'IA joue : " + input);
                    }
                    j2.addCoupJoues(input);
                    nature = j2.natureJoueur;
                    playersTurn--;
                }

                s.setPoint(x, y, nature);
                s.display(0);
                s.getAllPlayedCase();
            }
            s.checkIfWin();
        }
    }

    /**
     * Est utilisé une fois au demarage de chaque partie pour choisir la taille du plateau et le nombre de joueurs
     *
     * @return 0
     */
    public static int bootMain() {
        UI m = new UI();
        if (boot) {
            boot = false;
            intro();
            return (m.taillePlateau());
        }
        return 0;
    }

    /**
     * Supprime tout les coups joués par les joueurs
     */
    public void clearCoupJoues(){
        jH.coupJoues.clear();
        j2.coupJoues.clear();
    }

    /**
     * Introduction + Choix de l'adversaire et des noms
     */
    public static void intro() {
        UI m = new UI();
        String adversaire;
        boolean boucle = true;

            System.out.println("\n\n");
            System.out.println("                ** Bienvenue au jeu du Gomoku ** \n"+
                                "-Pour gagner il faut aligner 5 pions dans n'importe quel direction\n"+
                                "-Si jamais vous êtes bloqué(e) vous pouvez utiliser la commande /aide \n\n"+
                                "Aller, c'est parti !\n\n"+
                                "Voulez-vous jouer contre l'ordinateur(O) ou contre un humain(H) ? ");
        while (boucle) {
            adversaire = in.nextLine().trim();
            try {
                char choixAdversaire = adversaire.charAt(0);
                if (choixAdversaire == 'H' || choixAdversaire == 'h') {
                    j2 = new Joueur("Joueur2", 1, 'O', false);
                    jH.nomJoueur = m.choixNomJoueur(1);
                    j2.nomJoueur = m.choixNomJoueur(2);
                    boucle = false;
                } else if (choixAdversaire == 'O' || choixAdversaire == 'o') {
                    j2 = new Joueur(playerIA.getName(), 1, 'O', true);
                    jH.nomJoueur = m.choixNomJoueur(1);
                    j2.nomJoueur = j2.getNomJoueur();
                    boucle = false;
                } else {
                    System.out.println("erreur: la valeur entrée n'est pas valable");
                }
            } catch (Exception e) {
                System.out.println("erreur: la valeur entrée n'est pas valable");
                //System.out.println("erreur: la valeur entrée n'est pas valable "+e);
            }
        }
    }

    public String getJoueurFromChar(char symbole) {
        if (symbole == jH.getNature()) {
            return jH.getNomJoueur();
        } else {
            return j2.getNomJoueur();
        }
    }

    /**
     * Affiche tout les coups joués de chaques joueurs à la fin
     */
    public void afficherToutLesCoupsJoues(){
        System.out.println("Tout les coups joués dans cette partie : ");

        ArrayList<String> coupJoues = new ArrayList<>();
        String nom = jH.nomJoueur;
        String nom2 = j2.nomJoueur;
        String indent = "              "; // 20 spaces.
        int l;
        int add1 = nom.length()/2;
        int add2 = nom2.length()/2;

        if (nom.length() == 1){
            nom = " " + nom + indent.charAt(0);
            add1 = 1;
        } else if (nom.length() == 2){
            nom += indent.charAt(0);
        }

        l = nom2.length();
        nom2 = " " + nom2;
        if (l == 1){
            nom2 += " |";
            add2 = 1;
        } else if (l == 2){
            nom2 += indent.substring(0, 2) + "|";
        } else {
            nom2 += " |";
        }
        System.out.println("| "+nom+" |"+nom2);

        coupJoues.addAll(jH.coupJoues);
        coupJoues.addAll(j2.coupJoues);

        for (int p1 = 0, p2 = (jH.coupJoues).size(); p1 < (jH.coupJoues).size() || p2 < (jH.coupJoues).size()+(j2.coupJoues).size(); p1++, p2++) {

            String coord1 = "";
            String coord2 = "";

            if (p2 == (jH.coupJoues).size()+(j2.coupJoues).size()) {
                coord1 = coupJoues.get(p1);
            }
            else if(p1 == (jH.coupJoues).size()) {
                coord2 = coupJoues.get(p2);
            }
            else {
                coord1 = coupJoues.get(p1);
                coord2 = coupJoues.get(p2);
            }

            l = coord1.length();
            coord1 = indent.substring(0, add1) + coord1 + indent.substring(0, add1);
            if(l == 2) coord1 += " ";

            l = coord2.length();
            coord2 = indent.substring(0, add2) + coord2 + indent.substring(0, add2);
            if (l == 2) coord2 += " ";


            if (p2 == (jH.coupJoues).size()+(j2.coupJoues).size()) System.out.println("|"+coord1+"| "+indent.substring(0,(j2.nomJoueur).length()+1)+" |");
            else if(p1 == (jH.coupJoues).size()) System.out.println("| "+indent.substring(0,(jH.nomJoueur).length())+" |"+coord2+"|");
            else System.out.println("|"+coord1+"|"+coord2+"|");

        }
    }
}
Screen.java Unicode text, UTF-8 text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
package jeu;

import java.util.ArrayList;
import java.util.Scanner;

public class Screen {

    private Main m = new Main();
    private Conversion c = new Conversion();
    static private Scanner in = new Scanner(System.in);

    private final int size;
    private static Case[][] image;

    private boolean win = false;

    private final static char[] alphabet = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
            'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
            
    String[] direction = {
        "NORD-OUEST",
        "NORD",
        "NORD-EST",
        "EST", 
        "SUD-EST",
        "SUD",
        "SUD-OUEST",
        "OUEST"
    };


    /**
     * Constructeur de la classe Screen
     * 
     * @param size_ la taille voulue par l'utilisateur
     */
    Screen(int size_) {
        size = size_;
        image = new Case[size * 2][size];
    }

    /**
     * Renvoie l'image de l'objet screen en question
     * 
     * @return l'image
     */
    public Case[][] getImage() {
        return image;
    }

    /**
     * Verifie si la valeur entrée par l'utilisateur est valable
     * 
     * @param letter la partie 'lettre' de l'entrée
     * @param chiffre la partie 'chiffre/nombre' de l'entrée
     * @return true si la valeur est valable
     */
    public boolean checkUserInput(char letter, int chiffre) {
        String play = letter + String.valueOf(chiffre);
        int value = new String(alphabet).indexOf(letter);

        if (value != -1 && 0 < chiffre && chiffre <= size) {
            ArrayList<String> possiblesMovesString;
            possiblesMovesString = getStringListFromCaseList(getAllPossiblePlays(false));

            if (possiblesMovesString.contains(play)) {
                // System.out.println("Possible");
                return true;
            } else {
                System.out.println("Le coup " + play + " n'est pas jouable");
                return false;
            }
        }
        System.out.println("Le coup " + play + " n'est pas valable");
        return false;
    }


    public boolean checkIfCasePossible(char letter, int chiffre) {
        String play = letter + String.valueOf(chiffre);
        int value = new String(alphabet).indexOf(letter);

        if (value != -1 && 0 < chiffre && chiffre <= size) {
            ArrayList<String> possiblesMovesString;
            possiblesMovesString = getStringListFromCaseList(getAllPossiblePlays(false));

            if (possiblesMovesString.contains(play)) {
                // System.out.println("Possible");
                return true;
            } else {
                possiblesMovesString = getStringListFromCaseList(getAllPlayedCase());
                return possiblesMovesString.contains(play);
            }
        }
        return false;
    }

    /**
     * Converti une list de Case en list de Strings
     *
     * @param possibleMoves liste de case des coups possibles
     * @return possiblesMovesString liste de Strings des coups possibles
     */
    public ArrayList<String> caseListToStringList(ArrayList<Case> possibleMoves) {
        ArrayList<String> possiblesMovesString = new ArrayList<>();
        for (Case case1 : possibleMoves) {
            possiblesMovesString.add(getStringFromCase(case1));
        }
        return possiblesMovesString;
    }

    /**
     * donne la position d'une lettre dans l'alphabet
     * @param letter    la lettre a chercher dans l'alphabet
     * @return la position d'une lettre dans l'alphabet - 1
     */
    public int getPositionOfLetter(char letter){
        return(new String(alphabet).indexOf(letter));
    }

    /**
     * Place un pion sur le plateau avec sa nature
     * 
     * @param letter la coordonnées 'lettre' du pion
     * @param chiffre la coordonées 'chiffre/nombre' du pion
     * @param nature sa nature
     */
    public void setPoint(char letter, int chiffre, char nature) {
        int x = getPositionOfLetter(letter);
        if (x == 0) {
            x++;
        } else if (x == 1) {
            x = x + 2;
        } else {
            x = x * 2 + 1;
        }
        image[x][chiffre - 1].setNature(nature);
    }

    /**
     * Supprime tout les pions sur le terrain
     */
    public void clear() {
        for (int r = 0; r < size; r++) {
            for (int c = 0; c < size * 2; c++) {
                image[c][r] = new Case(' ');
            }
        }
    }

    /**
     * Affiche le terrain avec les pions joués
     *
     * @param command permet d'ajouter des options lors de l'affichage
     */
    public void display(int command) {
        int i = 0;

        ArrayList<String> possiblesMovesString;
        possiblesMovesString = getStringListFromCaseList(getAllPossiblePlays(false));

        ArrayList<String> texte = new ArrayList<>();
        texte.add("/aide        : affiche l'aide");
        texte.add("/joues       : affiche les coups joués par joueur");
        texte.add("/plateau     : affiche le plateau");
        texte.add("/redemarrer  : redemarre la partie");
        texte.add("/quit        : stop la partie");

        for (String string : possiblesMovesString) {
            setPoint(c.getCharFromString(string), c.getIntFromString(string), '-');
        }
        
        displayLetters();
        displayBar();

        for (int r = 0; r < size; r++) {
            String lineNum = Integer.toString(r + 1);
            if (r < 9) {
                lineNum = (" " + (r + 1));
            }
            System.out.print(lineNum + "|");
            for (int c = 0; c < size * 2; c++) {
                System.out.print(image[c][r].nature);
            }

            if (command == 1) {
                if (i != 4) {
                    System.out.println(" |      " + texte.get(r));
                    i++;
                } else {
                    System.out.println(" |");
                }
            } else {
                System.out.println(" |");
            }
        }

        for (String string : possiblesMovesString) {
            setPoint(c.getCharFromString(string), c.getIntFromString(string), ' ');
        }
        displayBar();
    }

    /**
     * Dessine la barre supérieure et inférieur (ex: +-------------------+)
     */
    private void displayBar() {
        System.out.print("  +");
        for (int c = 0; c < size * 2; c++) {
            System.out.print("-");
        }
        System.out.println("-+");
    }

    /**
     * Dessine les lettres des colonnes
     */
    private void displayLetters() {
        System.out.print("   ");
        for (int i = 0; i < size; i++) {
            System.out.print(" " + alphabet[i]);
        }
        System.out.println();
    }

    /**
     * Retourne un String de position (ex: A5) en partant de coordonées dans le tableau de case
     * 
     * @param x la coordonée en x
     * @param y la coordonée en y
     * @return la position de la Case
     */
    static public String getStringFromInt(int x, int y) {
        return alphabet[x / 2] + String.valueOf(y + 1);
    }

    /**
     * Renvoie la case correspondant à la position (ex: A5) donnée
     *
     * @param string_ la position donnée
     * @return la Case correspondante
     */
    public static Case getCaseFromString(String string_) {
        char letter = string_.charAt(0);
        int indexOfLetter = (new String(alphabet).indexOf(letter)) *2 +1;
        int number = Integer.parseInt(String.valueOf(string_.charAt(1)))-1;
        //System.out.println("index of letter '" + letter + "'  = "+indexOfLetter+"    NUMBER ="+number+"    CASE DANS METHODE == "+image[indexOfLetter][number].getNature());
        try {
            return image[indexOfLetter][number];
        } catch (Exception e){
            //System.out.println("erreur : getCaseFromString : "+e);
        }
        return image[indexOfLetter][number-1];
    }

    /**
     * Renvoie la position (ex: A5) correspondant à une Case donnée
     *
     * @param case_ la Case donnée
     * @return la position de la Case correspondante
     */
    public static String getStringFromCase(Case case_) {
        String letter = "";
        String nb = "";
        for (int i = 0; i < image.length; i++) {
            for (int j = 0; j < image[i].length; j++) {
                if (image[i][j] == case_) {
                    letter = Character.toString(alphabet[i / 2]);
                    nb = String.valueOf(j + 1);
                }
            }
        }
        return letter.concat(nb);
    }

    /**
     * Renvoie les positions (ex: A5) correspondantes à plusieurs Cases données
     * 
     * @param caseList les Cases données
     * @return les positions des Cases correspondantes
     */
    public ArrayList<String> getStringListFromCaseList(ArrayList<Case> caseList) {
        ArrayList<String> possiblesMovesString = new ArrayList<>();
        for (Case currentCase : caseList) {
            possiblesMovesString.add(getStringFromCase(currentCase));
        }
        return possiblesMovesString;
    }

    /**
     * Retourne le nombre de coups joués jusqu'ici dans la partie
     *
     * @return le nombre de coups joués
     */
    public int getNbCoupsJoues() {
        int nb = 0;
        for (Case[] cases : image) {
            for (Case aCase : cases) {
                if (aCase.getNature() != ' ') {
                    nb++;
                }
            }
        }
        if (nb == size*size){
            System.out.println("Tout les coups possibles ont était joués, la partie est terminée !");
            restart();
            return 0;
        }
        return nb;
    }

    /**
     * Retourne une liste des coups jouable actuellement dans la partie
     * 
     * @param afficher option permettant d'afficher ou pas la liste sous forme textuelle des coups jouables
     * @return la liste de Cases jouables
     */
    public ArrayList<Case> getAllPossiblePlays(boolean afficher) {
        ArrayList<Case> possibleMoves = new ArrayList<>();
        ArrayList<Case> adjacentCases = new ArrayList<>();
        int nbCoupsJoues = getNbCoupsJoues();

        possibleMoves.clear();

        // If there's at least one move already played
        if (nbCoupsJoues >= 1) {

            // Check every cases
            for (int i = 0; i < image.length; i++) {
                for (int j = 0; j < image[i].length; j++) {

                    // If it finds a non empty case
                    if (image[i][j].getNature() != ' ') {
                        nbCoupsJoues++;
                        adjacentCases.clear();

                        // Check all around the case to see if there's another case
                        for (int a = -2; a <= 2; a = a + 2) {
                            for (int b = -1; b <= 1; b++) {
                                // If a case exists, add it
                                try {
                                    if (image[i + a][j + b] != null && image[i + a][j + b] != image[i][j] && image[i + a][j + b].nature == ' ') {
                                        adjacentCases.add(image[i + a][j + b]);
                                    }
                                } catch (Exception e) {
                                    // System.out.println("Erreur: " + e);
                                }
                            }
                        }
                        // Then, for each non empty case, add the adjacent cases to the list of possible
                        // moves
                        possibleMoves.addAll(adjacentCases);
                    }
                }
            }

        // Else (if there are no move already played)
        } else {
            // Add all cases
            for (int i = 0; i < image.length; i = i + 2) {
                for (int j = 0; j < image[i].length; j++) {
                    possibleMoves.add(image[i][j]);
                }
            }
        }
        if (possibleMoves.size() == image.length * image.length) {
            System.out.println("Play anywhere");

        } else if (afficher) {
            System.out.println("You can play at : ");
            for (Case c : possibleMoves) {
                System.out.println(getStringFromCase(c));
            }
        }
        return possibleMoves;
    }

    /**
     * Permet de se déplacer dans le tableau en suivant une direction
     *
     * @param current la Case de départ
     * @param dir_ la direction à suivre
     * @return la position de la Case d'arrivée
     */
    public String moveWithDir(Case current, String dir_) {

        int coX = 0;
        int coY = 0;

        for (int i = 1; i < image.length; i = i + 2) {
            for (int j = 0; j < image[i].length; j++) {
                if (image[i][j] == current) {
                    coX = i;
                    coY = j;
                }
            }
        }

        switch (dir_) {
            case "NORD-OUEST":
                coX=coX-2;
                coY--;
                break;
            case "NORD-EST":
                coX=coX+2;
                coY--;
                break;
            case "SUD-OUEST":
                coX=coX-2;
                coY++;
                break;
            case "SUD-EST":
                coX=coX+2;
                coY++;
                break;
            case "NORD":
                coY--;
                break;
            case "SUD":
                coY++;
                break;
            case "OUEST":
                coX=coX-2;
                break;
            case "EST":
                coX=coX+2;
                break;
        }
        if (coY >= 0 && coY <= image.length && coX > 0 && coX < image.length) {
            return getStringFromInt(coX, coY);
        } else {
            return "er";
        }
    }

    /**
     * Renvoie toutes les cases où un coup a été joué
     *
     * @return une liste de toutes les cases jouées
     */
    public ArrayList<Case> getAllPlayedCase() {
        ArrayList<Case> allPlayed = new ArrayList<>();

        for (int i = 1; i < image.length; i = i + 2) {
            for (int j = 0; j < image[i].length; j++) {
                if (image[i][j].getNature() != ' ') {
                    allPlayed.add(image[i][j]);
                }
            }
        }
        return allPlayed;
    }

    /**
     * Vérifie si en partant d'une case et en suivant une direction, on obtient une condition de victoire
     *
     * @param current la case actuelle
     * @param dir la direction de vérification
     * @param nb le nombre de cases similaires déjà rencontrées
     */
    public void checkIfWinFromCase(Case current, String dir, int nb) {
        char symbole = current.nature;
        String afterMoving = moveWithDir(current, dir);
        if (!afterMoving.equals("er")) { //si il n'y a pas d'erreur on continue dans le if

            if (getCaseFromString(afterMoving) != null) {
                Case newCase = getCaseFromString(afterMoving);

                if (newCase.nature == symbole && checkIfCasePossible(c.getCharFromString(afterMoving),c.getIntFromString(afterMoving))) {
                    nb++;
                    if (nb == 5 && newCase.nature == symbole) {
                        win = true;
                    } else {
                        checkIfWinFromCase(newCase, dir, nb);
                    }
                }
            }
        }
    }

    /**
     * Vérifie si le plateau actuel présente une victoire pour un joueur
     */
    public void checkIfWin() {

        ArrayList<Case> allPlayed = getAllPlayedCase();

        allPlayed.forEach(current -> {
            for (String dir_ : direction) {
                checkIfWinFromCase(current, dir_, 1);
                if (win) {
                    System.out.println("Bravo "+m.getJoueurFromChar(current.nature)+" vous avez gagné(e) !! \n");
                    m.afficherToutLesCoupsJoues();
                    restart();
                    win=false;
                }
            }
        });
    }

    /**
     * Permets de redémarrer (ou non) une partie
     */
    public void restart(){
        System.out.println("\nVoulez-vous rejouer ? O/N");
        String commande = in.nextLine().trim();
        if (commande.equals("O") || commande.equals("o") || commande.equals("oui") || commande.equals("Oui")){
            clear();
            m.clearCoupJoues();
            System.out.println("\nAller c'est reparti !\n");
        } else {
            System.out.println("Merci d'avoir joué au gomoku fait par Roméo Tesei et Fil Veith,\nBonne Journée et à bientôt,");
            System.exit(0);
        }
    }
}
UI.java Unicode text, UTF-8 text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package jeu;

import java.io.PrintStream;
import java.util.List;
import java.util.Scanner;

public class UI {

    static private Scanner in = new Scanner(System.in);
    static private PrintStream out = System.out;

    /**
     * Choix de la taille du plateau
     * 
     * @return la taille du plateau
     */
    public int taillePlateau() {
        int taillePlateauInt = 10;
        out.println("Quel taille de plateau voulez-vous ? (entre 5 et 26)");    //si aucune valeur de l'utilisateur alors taille = 10
        while (true) {
            String taillePlateau = in.nextLine().trim();
            try {
                taillePlateauInt = Integer.parseInt(taillePlateau);
            } catch (Exception e) {
                out.println("erreur: la valeur entrée n'est pas valable ");
            }

            if (taillePlateauInt <= 26 && taillePlateauInt >= 5) {
                return taillePlateauInt;
            }
            out.println("erreur: la valeur entrée n'est pas valable ");
        }
    }

    /**
     * Choix du nom du joueur
     * 
     * @param nbJoueur le numéro du joueur (1 ou 2)
     * @return le nom de joueur
     */
    public String choixNomJoueur(int nbJoueur) {
        out.println("Nom du joueur " + nbJoueur + " : ");
        String nomJoueur = in.nextLine().trim();
        if (nomJoueur.equals(""))
            nomJoueur = "Joueur" + nbJoueur;
        return nomJoueur;
    }

    /**
     * Methode permettant d'afficher le necessaire au(x) joueur(s)
     *
     * @param nomJoueur le nom du joueur actuel
     * @param coupJoues la liste des coups joués par le joueur actuel
     * @param screen_ le screen actuel
     * @return l'interaction avec le joueur
     */
    public String userInterface(String nomJoueur, List<String> coupJoues, Screen screen_) {
        Main m = new Main();
        boolean boucler = true;
        while (boucler) {
            out.println("Où voulez vous jouer " + nomJoueur + " ? ");
            String commande = in.nextLine().trim();
            out.println("\n\n");
            switch (commande) {
            case "/quit":
                out.println("-> Bye.");
                boucler = false;
                System.exit(0);
            case "/aide":
                screen_.display(1);
                break;
            case "/plateau":
                screen_.display(0);
                break;
            case "/coup":
                screen_.getAllPossiblePlays(true);
                break;
            case "/redemarrer":
                screen_.clear();
                m.clearCoupJoues();
                screen_.display(0);
                break;
            case "/joues":
                for (String cJ : coupJoues) {
                    out.println("" + cJ);
                }
                out.println();
                break;
            default:
                if (commande.length() == 2 || commande.length() == 3) {
                    return commande;
                }
                out.println("-> commande inconnue '" + commande + "'");
                break;
            }
        }
        return "";
    }
}
makefile Unicode text, UTF-8 text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
L := $(wildcard ../*/*.lua)
P := $(wildcard ../*/*.py)
run:
ifdef L
	@lua $L
else ifdef P
	@python3 $P
else
	@echo Merde, il n\'y a pas d\'entrée lua ou python
endif

round #43

submitted at
3 likes

guesses
comments 0

post a comment


index.html ASCII text
p5.min.js Unicode text, UTF-8 text, with very long lines (65497)
sketch.js ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
let Rslider;
let rslider;
let dslider;
function setup() {
  createCanvas(400, 400);
  background(0);
  Rslider = createSlider(0, 30, 5);
  Rslider.position(20, 20);
  rslider = createSlider(-15, 15, 3);
  rslider.position(220, 20);
  dslider = createSlider(0, 30, 5);
  dslider.position(20, 360);
}

const gcd = (a, b) => b == 0 ? a : gcd (b, a % b)
const lcm = (a, b) =>  a / gcd (a, b) * b
function hypoX(R, r, d, theta) {
  if (R == r) { return d * cos(theta); }
  return (R - r) * cos(theta) + d * cos((R - r) / r * theta);
}
function hypoY(R, r, d, theta) {
  if (R == r) { return d * sin(theta); }
  return (R - r) * sin(theta) - d * sin((R - r) / r * theta);
}

function scale_and_draw(R, r, d, rot) {
  let extent = TWO_PI * lcm(r, R) / R;
  let k = (width / 2 - 10) / (R - r + d);
  if (r > R) {
    k = (width / 2 - 10) / (r - R + d);
  }
  R *= k; r *= k; d *= k;
  
  noFill();
  beginShape();
  for(let i = 0; i < 1000; i++) {
    let x = hypoX(R, r, d, extent / 1000 * i);
    let y = hypoY(R, r, d, extent / 1000 * i);
    let acc_factor = mag(x, y);
    let wobble_dir = TWO_PI - TWO_PI * noise(5 * rot, x / 200, y / 200);
    let x_temp = x * cos(rot) - y * sin(rot) + 5 * cos(wobble_dir);
    y = x * sin(rot) + y * cos(rot) + 5 * sin(wobble_dir);
    x = x_temp;
    
    vertex(x + width / 2, y + height / 2);
  }
  endShape(CLOSE);
}

let rotation = 0;
let smooth_vel = 0.001;
function draw() {
  let R = Rslider.value();
  let r = rslider.value();
  if (r == 0) { r = 1/2; }
  let d = dslider.value();
  background(0, 100);
  strokeWeight(2);
  stroke(255);
  let vel = mag(movedX / width, movedY / height);
  vel *= vel * 3;
  vel += 0.001;
  smooth_vel = 0.9 * smooth_vel + 0.1 * vel;
  scale_and_draw(R, r, d, rotation, smooth_vel);
  rotation += smooth_vel;
}
style.css ASCII text
1
2
3
4
5
6
7
html, body {
  margin: 0;
  padding: 0;
}
canvas {
  display: block;
}

round #42

submitted at
3 likes

guesses
comments 0

post a comment


2048.c ASCII text, with very long lines (302)
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#define _ -1
int board[16] = {
//  +-------+-------+-------+-------+
//  |       |       |       |       |
         -1 ,    -1 ,    -1 ,    -1 ,
//  |       |       |       |       |
//  +-------+-------+-------+-------+
//  |       |       |       |       |
         -1 ,    -1 ,    -1 ,     2 ,
//  |       |       |       |       |
//  +-------+-------+-------+-------+
//  |       |       |       |       |
         -1 ,     2 ,    -1 ,    -1 ,
//  |       |       |       |       |
//  +-------+-------+-------+-------+
//  |       |       |       |       |
         -1 ,    -1 ,    -1 ,    -1 ,
//  |       |       |       |       |
//  +-------+-------+-------+-------+
};

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef NEW_GAME
#define val(i, j) board[i * 4 + (0 + j)]
#endif
#ifdef LEFT
#define val(i, j) board[i * 4 + (0 + j)]
#endif
#ifdef RIGHT
#define val(i, j) board[i * 4 + (3 - j)]
#endif
#ifdef DOWN
#define val(i, j) board[i + (3 - j) * 4]
#endif
#ifdef UP
#define val(i, j) board[i + (0 + j) * 4]
#endif
#define s(x) #x
#define S(x) #x " " s(x)

#define AA "#define "
#define AB "//  |       |       |       |       |\n"
#define AC "//  +-------+-------+-------+-------+\n"
#define AD int gameOver() {
#define AE for(int i = 0; i < 4; i++) {
#define AF int prevRow = -1; int prevCol = -1;
#define AG for(int j = 0; j < 4; j++) {
#define AL } } return 1; }

#define AM void addRandom() {
#define AN while(1) { int index = rand() % 16;
#define AO if(board[index] == -1) {
#define AP board[index] = rand() % 100 < 90 ? 2 : 4;
#define AQ return; } } }

#define AR int move() {
#define AS int changed = 0;
#define AT for(int i = 0; i < 4; i++) {
#define AU int k = 0;
#define AV for(int j = 1; j < 4; j++) {
#define BD } else { k++;
#define BG } } } } return changed; }

#define BH void newGame() {
#define BI for(int i = 0; i < 16; i++) {
#define BJ board[i] = -1;
#define BK } addRandom(); addRandom(); }

#define BL int main() {
#define BM "//  +------ *** Game Over *** ------+\n"
#define BN char* mid = (gameOver() ? "//  +------ *** Game Over *** ------+\n" : "//  +-------+-------+-------+-------+\n");
#define BO newGame();
#define BP srand(time(((void *)0)));
#define BQ if(move()) addRandom();
#define BR ,
#define BS "%1$s%2$s\nint board[16] = {\n%3$s%4$s%5$11d ,%6$6d ,%7$6d ,%8$6d ,\n"
#define BT "%4$s%3$s%4$s%9$11d ,%10$6d ,%11$6d ,%12$6d ,\n%4$s%3$s%4$s%13$11d ,%14$6d ,%15$6d ,%16$6d ,\n"
#define BU "%4$s%3$s%4$s%17$11d ,%18$6d ,%19$6d ,%20$6d ,\n%4$s%3$s};\n\n"
#define BV "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n"
#define BW "#ifdef NEW_GAME\n#define val(i, j) board[i * 4 + (0 + j)]\n#endif\n"
#define BX "#ifdef LEFT\n#define val(i, j) board[i * 4 + (0 + j)]\n#endif\n"
#define BY "#ifdef RIGHT\n#define val(i, j) board[i * 4 + (3 - j)]\n#endif\n"
#define BZ "#ifdef DOWN\n#define val(i, j) board[i + (3 - j) * 4]\n#endif\n"
#define CA "#ifdef UP\n#define val(i, j) board[i + (0 + j) * 4]\n#endif\n"
#define CB "#define s(x) #x\n#define S(x) #x \" \" s(x)\n\n"
#define CC "%1$s%21$s\n%1$s%22$s\n%1$s%23$s\n%1$s%24$s\n%1$s%25$s\n%1$s%26$s\n"
#define CD "%1$s%27$s\n%1$s%28$s\n\n%1$s%29$s\n%1$s%30$s\n%1$s%31$s\n%1$s%32$s\n"
#define CE "%1$s%33$s\n\n%1$s%34$s\n%1$s%35$s\n%1$s%36$s\n%1$s%37$s\n%1$s%38$s\n"
#define CF "%1$s%39$s\n%1$s%40$s\n\n%1$s%41$s\n%1$s%42$s\n%1$s%43$s\n%1$s%44$s\n\n"
#define CG "%1$s%45$s\n%1$s%46$s\n%1$s%47$s\n%1$s%48$s\n%1$s%49$s\n%1$s%50$s\n#define BR ,\n"
#define CH "%1$s%51$s\n%1$s%52$s\n%1$s%53$s\n%1$s%54$s\n%1$s%55$s\n%1$s%56$s\n"
#define CI "%1$s%57$s\n%1$s%58$s\n%1$s%59$s\n%1$s%60$s\n%1$s%61$s\n"
#define CJ "%1$s%62$s\n%1$s%63$s\n%1$s%64$s\n%1$s%65$s\n%1$s%66$s\n%1$s%67$s\n"
#define CK "%1$s%68$s\n%1$s%69$s\n%1$s%70$s\n%1$s%71$s\n%1$s%72$s\n%1$s%73$s\n"
#define CL "%1$s%74$s\n%1$s%75$s\n%1$s%76$s\n%1$s%77$s\n%1$s%78$s\n%1$s%79$s\n"
#define CM "%1$s%80$s\n%1$s%81$s\n%1$s%82$s\n%1$s%83$s\n%1$s%84$s\n%1$s%85$s\n"
#define CN "%1$s%86$s\n%1$s%87$s\n%1$s%88$s\n%1$s%89$s\n%1$s%90$s\n%1$s%91$s\n"
#define CO "%1$s%92$s\n%1$s%93$s\n%1$s%94$s\n%1$s%95$s\n%1$s%96$s\n%1$s%97$s\n"
#define CP "%1$s%98$s\n%1$s%99$s\n%1$s%100$s\n%1$s%101$s\n%1$s%102$s\n%1$s%103$s\n"
#define CQ "%1$s%104$s\n%1$s%105$s\n%1$s%106$s\n"
#define CR ""
#define CS "AD\nAE\nAF\nAG\nif(val(i, j) == _ || val(i, j) == prevRow) return 0;\nprevRow = val(i, j);\nif(val(j, i) == _ || val(j, i) == prevCol) return 0;\nprevCol = val(j, j);\nAL\nAM\nAN\nAO\nAP\nAQ\nAR\nAS\nAT\n"
#define CT "AU\nAV\nif (val(i, j) == _) continue;\nif (val(i, k) == _) {\nval(i, k) = val(i, j);\nval(i, j) = _; changed = 1;\n} else if (val(i, k) == val(i, j)) {\nval(i, k) += val(i, j);\nval(i, j) = _; k++; changed = 1;\nBD\nval(i, k) = val(i, j);\nif(k != j) { val(i, j) = _;\nBG\nBH\nBI\nBJ\nBK\n"
#define CU "BL\nBN\n#ifdef NEW_GAME\nBO\n#else\nBP\nBQ\n#endif\nprintf(\nBS\nBT\nBU\n"
#define CV "BV\nBW\nBX\nBY\nBZ\nCA\nCB\nCC\nCD\nCE\nCF\nCG\nCH\nCI\nCJ\nCK\nCL\n"
#define CW "CM\nCN\nCO\nCP\nCQ\nCR\nCS\nCT\nCU\nCV\nCW\nCX,\nCY\nCZ\nDA\nDB\nDC\n"
#define CX "DD\nDE\nDF\nDG\nDH\nDI\nDJ\nDK\nDL\nDM\nDN\nDO\nDP\nDQ\nDR\nDS\nDT\nDU);}"
#define CY AA, S(_), AC, AB, board[0], board[1], board[2], board[3], board[4], board[5], board[6],
#define CZ board[7], board[8], board[9], board[10], board[11], board[12], board[13], board[14], board[15], S(AA),
#define DA S(AB), S(AC), S(AD), S(AE), S(AF), S(AG),
#define DB S(AL), S(AM), S(AN), S(AO), S(AP), S(AQ), S(AR), S(AS), S(AT), S(AU),
#define DC S(AV), S(BD),
#define DD S(BG), S(BH), S(BI), S(BJ), S(BK),
#define DE S(BL), S(BM), S(BN), S(BO),
#define DF S(BP), S(BQ), S(BS), S(BT), S(BU), S(BV), S(BW), S(BX), S(BY),
#define DG S(BZ), S(CA), S(CB), S(CC), S(CD), S(CE), S(CF), S(CG), S(CH), S(CI),
#define DH S(CJ), S(CK), S(CL), S(CM), S(CN), S(CO), S(CP), S(CQ), S(CR), S(CS),
#define DI S(CT), S(CU), S(CV), S(CW), S(CX), DK, DL, DM, DN, DO, DP, DQ, DR, DS,
#define DJ DT, DU, DV, S(DK), S(DL), S(DM), S(DN), S(DO), S(DP), S(DQ), S(DR), S(DS), S(DT), S(DU), S(DV),
#define DK "CY AA, S(_), AC, AB, board[0], board[1], board[2], board[3], board[4], board[5], board[6],"
#define DL "CZ board[7], board[8], board[9], board[10], board[11], board[12], board[13], board[14], board[15], S(AA),"
#define DM "DA S(AB), S(AC), S(AD), S(AE), S(AF), S(AG),"
#define DN "DB S(AL), S(AM), S(AN), S(AO), S(AP), S(AQ), S(AR), S(AS), S(AT), S(AU),"
#define DO "DC S(AV), S(BD),"
#define DP "DD S(BG), S(BH), S(BI), S(BJ), S(BK),"
#define DQ "DE S(BL), S(BM), S(BN), S(BO),"
#define DR "DF S(BP), S(BQ), S(BS), S(BT), S(BU), S(BV), S(BW), S(BX), S(BY),"
#define DS "DG S(BZ), S(CA), S(CB), S(CC), S(CD), S(CE), S(CF), S(CG), S(CH), S(CI),"
#define DT "DH S(CJ), S(CK), S(CL), S(CM), S(CN), S(CO), S(CP), S(CQ), S(CR), S(CS),"
#define DU "DI S(CT), S(CU), S(CV), S(CW), S(CX), DK, DL, DM, DN, DO, DP, DQ, DR, DS,"
#define DV "DJ DT, DU, DV, S(DK), S(DL), S(DM), S(DN), S(DO), S(DP), S(DQ), S(DR), S(DS), S(DT), S(DU), S(DV),"
AD
AE
AF
AG
if(val(i, j) == _ || val(i, j) == prevRow) return 0;
prevRow = val(i, j);
if(val(j, i) == _ || val(j, i) == prevCol) return 0;
prevCol = val(j, j);
AL
AM
AN
AO
AP
AQ
AR
AS
AT
AU
AV
if (val(i, j) == _) continue;
if (val(i, k) == _) {
val(i, k) = val(i, j);
val(i, j) = _; changed = 1;
} else if (val(i, k) == val(i, j)) {
val(i, k) += val(i, j);
val(i, j) = _; k++; changed = 1;
BD
val(i, k) = val(i, j);
if(k != j) { val(i, j) = _;
BG
BH
BI
BJ
BK
BL
BN
#ifdef NEW_GAME
BO
#else
BP
BQ
#endif
printf(
BS
BT
BU
BV
BW
BX
BY
BZ
CA
CB
CC
CD
CE
CF
CG
CH
CI
CJ
CK
CL
CM
CN
CO
CP
CQ
CR
CS
CT
CU
CV
CW
CX,
CY
CZ
DA
DB
DC
DD
DE
DF
DG
DH
DI
DJ
DK
DL
DM
DN
DO
DP
DQ
DR
DS
DT
DU);}
Makefile ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
NO_MOVE:
	@echo "use make <direction> to move the board in that direction"
	@echo "or make NEW_GAME to start a new game"

left: LEFT
LEFT:
	@gcc 2048.c -o 2048 -D LEFT -w
	@./2048 > 2048.c
	@head -n 19 2048.c | tail -n 17

right: RIGHT
RIGHT:
	@gcc 2048.c -o 2048 -D RIGHT -w
	@./2048 > 2048.c
	@head -n 19 2048.c | tail -n 17

up: UP
UP:
	@gcc 2048.c -o 2048 -D UP -w
	@./2048 > 2048.c
	@head -n 19 2048.c | tail -n 17

down: DOWN
DOWN:
	@gcc 2048.c -o 2048 -D DOWN -w
	@./2048 > 2048.c
	@head -n 19 2048.c | tail -n 17

new_game: NEW_GAME
NEW_GAME:
	@gcc 2048.c -o 2048 -D NEW_GAME -w
	@./2048 > 2048.c
	@head -n 19 2048.c | tail -n 17

round #38

submitted at
0 likes

guesses
comments 0

post a comment


38.lua ASCII text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
-- Problem:
--   I-style calculator: solve an expression with space-based precedence
--   https://cg.esolangs.gay/38/
-- Restrinctions:
--   Precedence only works for balanced spaces

op_match = "[%+%-%*/]"

function get_value(s, i, values)
  value = string.sub(s, i, i)
  if value == "x" then
    value = values[i]
  end
  return value
end

function arith(s, a, b, i)
  op = string.sub(s, i, i)
  if op == "+" then
    return a + b
  elseif op == "-" then
    return a - b
  elseif op == "*" then
    return a * b
  elseif op == "/" then
    return a / b
  end
  print("Fuck")
end

function update_values(i, n, values)
  max_k = 1
  for k, val in pairs(values) do
    if k > max_k then
      max_k = k
    end
  end

  for k = i, max_k do
    val = values[k]
    if val then
      values[k - n] = val
      values[k] = nil
    end
  end
end

function increase_prec(s, values)
  start, finish = string.find(s, "%s*%s", start)
  while start do
    s = string.sub(s, 1, finish - 1)..string.sub(s, finish + 1)
    update_values(finish, 1, values)
    start, finish = string.find(s, "%s*%s", finish)
  end
  return s
end

function eval_current(s, values)
  start, finish = string.find(s, "[x%d]"..op_match.."[x%d]")
  if not start then
    return s
  end
  first = get_value(s, start, values)
  second = get_value(s, finish, values)
  update_values(finish, 2, values)
  values[start] = arith(s, first, second, start+1)
  s = string.gsub(s, "[x%d]"..op_match.."[x%d]", "x", 1)
  return s
end

function eval_and_prec(s, values)
  temp = eval_current(s, values)
  while temp ~= s do
    s = temp
    temp = eval_current(s, values)
  end
  s = increase_prec(s, values)
  return s
end

function eval(s)
  values = {}
  temp = eval_and_prec(s, values)
  while temp ~= s do
    s = temp
    temp = eval_and_prec(s, values)
  end
  return values[1]
end

-- s = "9 / 1+2  -  1    /    2"
-- print(eval(s)) -- 1
-- s = "0-6 * 2"
-- print(eval(s)) -- -12
-- s = "4  /  1 + 1"
-- print(eval(s)) -- 2
-- s = "2-4/2"
-- print(eval(s)) -- -1
-- s = "1 + 2   *   3/3 + 2  +  3"
-- print(eval(s)) -- 18

s = io.read()
print(eval(s))

round #37

submitted at
1 like

guesses
comments 0

post a comment


one_liner.(,) ASCII text, with very long lines (9484), with CRLF line terminators
1
((),()()()()()()()()()()())(()(),(()))(()()()()()()()(),(())(())(())(())()()())(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,,,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(()()()()()()()())),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()()()()()),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()((()))((()))((()))((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()((()))((()))((()))((()))((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()((()))((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()((()))((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()()((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(()()()()()()()())),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()()((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))),,()()()()()()()()(()()()()()()()())((()))((()))((()))((()))((()))((()))((()))((()))((()))),,()()()()()()()()()()()()()()()()()()((()))((()))((()))((()))((()))((()))((()))((()))),,,(,,,,,()),(,,,,(,,,,,(),((()),((,,,,,())),,,,,(,((),(())()))))((()))((()))))(()()()()()()()()(),((()))((()))((()))((()))((()))((()))((()))((()))((())))(,(()()()()(),())(,,,,(,,,,,(()(),(()())())(()()(),(,,,,,()))(()()()(),())(()()()()()(),(()()()()()())(()()()()()()())((())))(()()()()()()(),(,,,,((()())),(()()()()()()()())(()()(),(()()())())(()()()(),(,,,,,())),()()()()()()()()()()())))(,,,,(,,,,,()),(,,,,(,,,,,()),(()()()()()()()),())(,,,,(()()()()()()()),()()()()()()()()()()(),())),(()()()()(),(,,,,,())))(,(()()()()()(),(()()()()()())())(()()()(),())(,,,,,(()()()()()(),(()()()()()())(()()()()()()()()()),,,(()()()()()()),()()()()()()()()()(()()()(),(,,,,,()))))(,,(()()()()()())),,,(()()),(()),())(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,(,,,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(()()()()()()()())((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()()((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()((()))((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()()()()()),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()((()))((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()()),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()((()))((()))((()))((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()((()))((()))((()))((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,()()()()()()()()()(()()()()()()()())((()))((()))((()))((()))((()))((()))((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()),,()()()()()()()()()()()()()()()()(()()()()()()()())((()))((()))((()))((()))((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))),,()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()()()()()()((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()((()))((()))((()))((()))((()))),,(()()()()()()()())(()()()()()()()())()()()()()()()()()()()()()()()()()()((()))((()))((()))),,()()()()()()()()(()()()()()()()())((()))((()))((()))((()))((()))((()))((()))((()))((()))),,()()()()()()()()()()()()()()()()()()((()))((()))((()))((()))((()))((()))((()))((()))),,,(()),(()())(),()),,,(()()()()()()()()()()()()),(,,,,,()),())

round #34

submitted at
3 likes

guesses
comments 0

post a comment


fizzbuzz.txt ASCII text, with very long lines (545)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
FizzBuzz program in vim
This program also requires python3 to run. For the purposes of this program the key strokes will be quoted in backticks. Keystrokes without plain text representation will be written in angle brackets. E.g. <Enter> means press the enter key, <Esc> means press the escape key. These are the only escape characters.

Setup:
Start vim, usually started in the shell with
`vim<Enter>`

Program:
When you are running vim and are in normal mode you can run the program.
`iprint("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizzBuzz\n31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizzBuzz\n46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nFizz\n58\n59\nFizzBuzz\n61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz\n71\nFizz\n73\n74\nFizzBuzz\n76\n77\nFizz\n79\nBuzz\nFizz\n82\n83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz")<Esc>V:!python3<Enter>`

round #33

submitted at
1 like

guesses
comments 0

post a comment


3sp.py ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# python3 3sp.py -h            |    |    | esolangin' on the lone desert highway
import                  argparse    ;    #
def      parse_contents(contents    )    :
    instructions               =    [    ]
    for          line in program    :    #
        for          instruction    in   line.split():
            try                     :    #
                instructionValue    =    int(instruction)
                instructions        .    append(instructionValue)
            except    ValueError    :    #
                return              instructions
    return          instructions    ;    #
def                pad(row, size    )    :
    if            size > len(row    )    :
        row               += [0]    *    (size - len(row))
def                       update    (    instruction, row):
    pad                     (row    ,    instruction + 1)
    pad                     (row    ,    row[instruction] + 1)
    pad                     (row    ,    row[row[instruction]] + 1)
    row                     [row    [    row[instruction ]]] += 1
def                    do_io(row    )    :
    pad                     (row    ,    4)
    if             row[1] % 2 ==    1    :
        print         (chr(row[3    ]    %256), end="")
def             run(instructions    ,    max_cycles, io):
    row                        =    [    ]
    cycles                     =    0    ;
    while                   True    :    #
        if            max_cycles    !=   None and cycles > max_cycles:
            if                io    :    #
                print        (""    )    ;
            return           row    ;    #
        index           = cycles    %    len(instructions)
        update     (instructions    [    index], row)
        if          index == len    (    instructions) - 1 and io:
            do_io           (row    )    ;
        cycles                +=    1    ;
    return                   row    ;    #
def                        repl(    )    :
    print                           (    "3 Star Programmer REPL")
    instructions               =    [    ]
    row                        =    [    ]
    while                   True    :    #
        try                         :    #
            instructionValue        =    int(input(">>> "))
            instructions            .    append(instructionValue)
            update                  (    instructionValue, row)
            print           (row    )    ;
        except        ValueError    :    #
            return                  ;    #
if        __name__ == '__main__'    :    #
    parser            = argparse    .    ArgumentParser(description="Three Star Programmer interpreter. https://esolangs.org/wiki/Three_Star_Programmer")
    parser         .add_argument    (    "filename", help="Leave empty to use as a REPL. Options have no effect on the REPL.", nargs="?")
    parser         .add_argument    (    "-s", "--max_steps", type=int, help="Limits the number of steps the program takes.")
    parser         .add_argument    (    "-o", "--output", action="store_true", help="Outputs according to the output extension.")
    parser         .add_argument    (    "-p", "--print_tape", action="store_true", help="Prints the memory each step.")
    args                = parser    .    parse_args()
    if                      args    .    filename == None:
        repl                   (    )    ;
    else                            :    #
        with           open(args    .    filename, "r") as f:
            program          = f    .    readlines()
        if       args.print_tape    :    #
            print           (run    (    parse_contents(program), args.max_steps, args.output))
        else                        :    #
            run  (parse_contents    (    program), args.max_steps, args.output)