祥琪游戏,也被称为中国象棋,是一种类似国际象棋的游戏,在中国、越南、台湾和其他东亚国家很流行。香旗两边的颜色是红的和黑的。香旗有16块黑点:1名将军(G)、2名顾问(A)、2名大象(E)、2匹马(H)、2辆战车(R)、2门大炮(C)和5名士兵(S)。垂直线称为文件(列),水平线称为秩(行)。
在“中国象棋手册”中部分描述并为几个计算机软件实现所用的符号系统以相对术语描述动作如下:
[single-letter piece abbreviation][former file][operator indicating direction of movement][new file, or in the case of purely vertical movement, number of ranks traversed]
文件号从每个玩家的右边数到每个玩家的左边。对于黑色,文件号显示在图片中,白色背景。
如果一个文件中有两个相同的部分,则使用符号+
(前面,较高的级别)和-
(后方,较低的级别)来代替以前的文件号。如果有两个以上,+
(最高等级),2
(第二最高等级),3
(第三最高等级),是使用的。如果存在两个以上,可以使用数字或-
来表示最低秩。如果多个文件包含多个相同的部分,则不能省略以前的文件和顺序,但可以省略片段缩写。
[former order in the file][single-letter piece abbreviation][operator indicating direction of movement][new file, or in the case of purely vertical movement, number of ranks traversed]
[former order in the file][former file][operator indicating direction of movement][new file, or in the case of purely vertical movement, number of ranks traversed]
加号(+
)用来表示向前移动。负号(-
)用于表示向后移动。圆点或圆点(.
)或等号(=
)用于表示水平或横向运动。对于对角线移动的部分,使用的是正负号,而不是句号。
因此,如果五名士兵在(5,6), (7,6), (9,6), (5,8), (7,8)
,那么每一名向前移动的士兵都被表示为-5+1, -7+1, S9+1, +5+1, +7+1
;(3,4)
和(3,8)
上的两匹分别向(4,6)
移动的马表示为-H+4
和+H-4
;五名士兵在(5,6), (7,6), (5,4), (5,8), (7,8)
,然后每个向前移动一个等级的马被表示为25+1, -7+1, 35+1, +5+1, +7+1
;在(3,4)
和(5,8)
上的两匹马分别被表示为D25和D26和d27。
给定要移动的块的当前位置和目标,以及包含相同类型的所有位置的列表/集合,输出其表达式。输入格式灵活。最短代码获胜。
示例:(使用移动数组第一项的格式)
S [(5,6), (7,6), (9,6), (5,8), (7,8)] (5,7) -> -5+1 or -S5+1
S [(7,6), (5,6), (9,6), (5,8), (7,8)] (7,7) -> -7+1 or -S7+1
S [(9,6), (5,6), (7,6), (5,8), (7,8)] (9,7) -> S9+1
S [(5,8), (5,6), (7,6), (9,6), (7,8)] (5,9) -> +5+1 or +S5+1
S [(7,8), (5,6), (7,6), (9,6), (5,8)] (7,9) -> +7+1 or +S7+1
H [(3,4), (3,8)] (4,6) -> -H+4
H [(3,8), (3,4)] (4,6) -> +H-4
H [(3,8)] (4,6) -> H3-4
S [(5,4), (5,8), (7,8), (5,6), (7,6)] (5,5) -> 35+1 or -5+1 or 3S5+1 or -S5+1
S [(5,6), (5,8), (7,8), (5,4), (7,6)] (5,7) -> 25+1 or 2S5+1
S [(5,8), (5,6), (7,8), (5,4), (7,6)] (5,9) -> +5+1 or +S5+1
从place(x0,y0),place(x,y)及其rules r,如果这有帮助的话,开始位置和移动规则:
G (5,1) r=1 & 3=y0 & (y>y0 | y>5)
发布于 2020-10-15 22:38:15
÷Qa9═wë•Θ╣äUuâ£▼+∙8WU▓kw≈▲!.┤α@∟┐₧╨═ºî⌂z▼0╬⌂6╕ú▄O&⌂¼^Mgâ╗╕.î¡☼:
接受输入作为 []
。
;x\EE-c:+"=+-"@s|aaE=s,h?$+Ydx]+MEsxh|I@|oc%vcaHX-xn^运行并调试它Explanation:第一部分计算最后一部分:移动方向和由此产生的排名文件/变化:;x\EE-c:+"=+-"@s|aaE=s,h?$+Yd
;x Push position after and before
\ Zip -> [[file after, file before], [rank after, rank before]]
E Push files and ranks separately
E- Difference in ranks (after - before)
c:+ Copy and get the sign (-1, 0, +1)
"=+-"@ Index into the string "=+-" (-1 means last one)
s|a Get the absolute value of the difference in rank
aE= Check whether file before = file after (pure vertical movement)
s Swap with abs of difference in rank
,h Get file after
? If file before = file after:
abs(rank after - rank before)
Else:
file after
(this is the number in the end)
$ Convert to string
+ Concat the sign (-=+) and number.
Yd Store in Y register and delete from stack.第二部分计算文件中的索引(+、-或数字):x]+MEsxh|I@|oc%vcaHX-xn^这意味着:如果在这个级别上没有其他的作品,“否则,如果我们有最高级别,"+“否则,如果我们的级别最低,"-“否则,排名的索引为字符串。这些条件以一种特殊的方式工作:首先,产生所有条件,最重要的是最不重要的条件,然后是第一个条件的true分支(索引为字符串)。在此之后,我们在执行条件?之前直接推送每个条件的falsy值,这对于最重要的条件来说是最不重要的。第三部分检查是否需要添加文件号:,b'S<*!,h$*
, Get the piece type
b Copy both the result of part 2 and the piece type
'S< Test whether the piece type is NOT "S"
(actually less than "S", because all other piece types come before S in ASCII)
* Repeat the result of part 2 by the result of this test:
"" if the piece type is "S"
the result of part 2 otherwise
! Negate this, "" is falsey.
=> This means NOT (part 2 is empty AND NOT piece type is "S")
=> Part 2 is empty iff this is the only piece in the file
=> NOT (only piece in file AND NOT piece type is "S")
=> NOT only piece in file OR piece type is "S"
,h Push the file before
$ and convert it to string
* Repeat that string by the result of above check:
"" unless other pieces in file or piece type is "S"因此,在第1-3部分之后,堆栈如下所示: Y寄存器包含运动本身(来自第1部分)。最后一部分将这些内容合并成一个字符串:++y+ "" "" ""
+ "" ""
+ ""
y "" ""
+ ""最后的结果是隐式输出。-?'+?z?,b'S<*!,h$*++y+C10K111Explanation:K212第一部分计算最后一部分:移动方向和由此产生的排名文件/变化:A13第二部分计算文件中的索引(D14、D15或数字):A16这意味着:F117H118如果在这个级别上没有其他的作品,“H219H120否则,如果我们有最高级别,"+“H221H122否则,如果我们的级别最低,"-“H223H124否则,排名的索引为字符串。H225F226这些条件以一种特殊的方式工作:首先,产生所有条件,最重要的是最不重要的条件,然后是第一个条件的D27分支(索引为字符串)。在此之后,我们在执行条件D28之前直接推送每个条件的falsy值,这对于最重要的条件来说是最不重要的。第三部分检查是否需要添加文件号:A29因此,在第1-3部分之后,堆栈如下所示:A30Y寄存器包含运动本身(来自第1部分)。最后一部分将这些内容合并成一个字符串:A31最后的结果是隐式输出。-?'+?z?
x]+ Append the position before to the list of other pieces
ME Push list of files, then list of ranks
s Swap the two
xh|I Find indices with file = file before
@ Get ranks of these
|o Calculate destination index of each element if the ranks were sorted
c%v Get length of the array - 1
(no. of other pieces in file)
ca Get the array of dest. indices again
HX Get the last index (= index of the moving pieces)
and store in register X
- Then subtract from the no. of other pieces
xn^ ... and increment the result
-> That's the index from big rank to small
$ ... and convert to string
'-? If register X = 0 (lowest rank): "-"
Else: The index from big to small
'+? If index from big to small = 0 (high rank): "+"
Else: Result from above
z? If length of array = 1: ""
Else: Result from above
这意味着:
F117H118
如果在这个级别上没有其他的作品,“
H219H120
否则,如果我们有最高级别,"+“
H221H122
否则,如果我们的级别最低,"-“
H223H124
否则,排名的索引为字符串。
H225F226
这些条件以一种特殊的方式工作:首先,产生所有条件,最重要的是最不重要的条件,然后是第一个条件的D27
分支(索引为字符串)。在此之后,我们在执行条件D28
之前直接推送每个条件的falsy值,这对于最重要的条件来说是最不重要的。
第三部分检查是否需要添加文件号:
A29
因此,在第1-3部分之后,堆栈如下所示:
A30
Y寄存器包含运动本身(来自第1部分)。
最后一部分将这些内容合并成一个字符串:
A31
最后的结果是隐式输出。
-?'+?z?,b'S<*!,h$*++y+
C10
K111
Explanation:K212
第一部分计算最后一部分:移动方向和由此产生的排名文件/变化:
A13
第二部分计算文件中的索引(D14
、D15
或数字):
A16
这意味着:
F117H118
如果在这个级别上没有其他的作品,“
H219H120
否则,如果我们有最高级别,"+“
H221H122
否则,如果我们的级别最低,"-“
H223H124
否则,排名的索引为字符串。
H225F226
这些条件以一种特殊的方式工作:首先,产生所有条件,最重要的是最不重要的条件,然后是第一个条件的D27
分支(索引为字符串)。在此之后,我们在执行条件D28
之前直接推送每个条件的falsy值,这对于最重要的条件来说是最不重要的。
第三部分检查是否需要添加文件号:
A29
因此,在第1-3部分之后,堆栈如下所示:
A30
Y寄存器包含运动本身(来自第1部分)。
最后一部分将这些内容合并成一个字符串:
A31
最后的结果是隐式输出。
https://codegolf.stackexchange.com/questions/165423
复制相似问题