Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

35
LINES

< > TinyBrain | #1010388 - Chess Network [dev.]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar - homepage

Libraryless. Click here for Pure Java version (14460L/103K).

!7

answer {
  makeBoard(parseFirstInt(s));
}

p {
  bot();
  print("Please type board size.");
  consoleSetInput("8");
}

svoid makeBoard(int size) {
  Web web = simpleWeb();
  for (int row = 1; row <= size; row++)
    for (char col = 'A'; col < (char) ('A'+size); col++) {
      rel(size, web, col, row, (char) (col+1), row, 'right);
      rel(size, web, col, row, (char) (col-1), row, 'left);
      rel(size, web, col, row, col, row+1, 'up);
      rel(size, web, col, row, col, row-1, 'down);
    }
  showWeb(web);
}

svoid rel(int size, Web web, char col1, int row1, char col2, int row2, S rel) {
  S a = cell(col1, row1, size), b = cell(col2, row2, size);
  if (nempty(a) && nempty(b))
    web_addRelation(web, a, b, rel);
}

sS cell(char col, int row, int size) {
  if (row >= 1 && row <= size && col >= 'A' && col < (char) ('A'+size))
    ret col + str(row);
  null;
}

download  show line numbers  debug dex   

Travelled to 3 computer(s): cfunsshuasjs, onxytkatvevr, tvejysmllsmz

No comments. add comment

Snippet ID: #1010388
Snippet name: Chess Network [dev.]
Eternal ID of this version: #1010388/13
Text MD5: 44c7fd6a55e4f44916c711400994aac5
Transpilation MD5: 19e41d452653530f767fe438eee7bcde
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-14 04:35:29
Source code size: 909 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 41 / 127
Version history: 12 change(s)
Referenced in: [show]