Support
Quality
Security
License
Reuse
kandi has reviewed polyglot and discovered the below as its top functions. This is intended to give you an instant insight into polyglot implemented functionality, and help decide if they suit your requirements.
Multilingual text (NLP) processing toolkit
Karate - Get CSV column value having space
* csv data =
"""
Instrument ID, Instrument Name
SS-01,TestData
"""
* match data[0]['Instrument ID'] == 'SS-01'
vim - How to Split single line Array literal into multiple lines?
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ "TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript" ]
:s/\s/\r/g
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
='[
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
nnoremap <key> :s/\s/\r/g<CR>='[
vi[ " visually select what's between the brackets
:'<,'>s/\%V\s/\r/g " substitute spaces contained in the visual
" selection with \r
vi[
:'<,'>s/\%V\s/§/g
:s/§/\r/g
='[
function! ExpandList()
silent s/\%V\s/§/g
silent s/§/\r/g
silent normal ='[
endfunction
xnoremap <key> :<C-u>call ExpandList()<CR>
function! ExpandList()
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim() })
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
function! ExpandList(type, ...)
silent s/\%V.*\%V/\="\r" . submatch(0)
\ ->split(',')
\ ->map({ i, v -> v->trim()})
\ ->join(",\r") . "\r"/g
silent normal ='[
endfunction
nnoremap <key> :set opfunc=ExpandList<CR>g@
-----------------------
[ |"TypeScript", "HTML", "CSS", "SQL", "JavaScript" ]
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
-----------------------
[ |"TypeScript", "HTML", "CSS", "SQL", "JavaScript" ]
[
"TypeScript",
"HTML",
"CSS",
"SQL",
"JavaScript"
]
renv + venv + jupyterlab + IRkernel: will it blend?
owd <- setwd(".."); source("renv/activate.R"); setwd(owd)
Minimax returning illegal uci move - move generation doesn't update?
def minimax(board, depth, is_max):
if depth == 0:
return evaluate(board)
elif board.fen in searched_position_evals:
# board.pop()
return searched_position_evals[board.fen]
...
Is there a way to use a java object as an argument for a function and return one of said objects's values in GraalJS?
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("polyglot.js.allowHostAccess", true);
import org.graalvm.polyglot.HostAccess;
// ...
@HostAccess.Export
public double getSpeed() {
return this.speed;
}
-----------------------
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("polyglot.js.allowHostAccess", true);
import org.graalvm.polyglot.HostAccess;
// ...
@HostAccess.Export
public double getSpeed() {
return this.speed;
}
How to use pomless tycho artifacts in non-tycho project
@echo off
set MVN_HOME=C:/Tools/apache-maven-3.6.3
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
set PATH=%MVN_HOME%/bin;%PATH%
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%~nH-SNAPSHOT -DgeneratePom=true -Dpackaging=jar -Dfile="%BUNDLES_HOME%/%%F/target/%%F-%%~nH-SNAPSHOT.jar"
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%H -DgeneratePom=true -Dpackaging=jar -Dfile="%ECLIPSE_HOME%/%%~nG.jar"
)
)
)
)
org.eclipse.ocl:org.eclipse.ocl
org.eclipse.ocl:org.eclipse.ocl.common
org.eclipse.ocl:org.eclipse.ocl.ecore
org.eclipse.ocl:org.eclipse.ocl.pivot
@echo off
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
break > deps-gen.txt
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%~nH-SNAPSHOT^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%H^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
)
)
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
:
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar \
-Dfile="$BUNDLES_HOME/$artifact/target/$artifact-$version.jar"
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar -Dfile="$file"
done
fi
done < deps.txt
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
: > deps-gen.txt
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
echo >> deps-gen.txt
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
done
fi
done < deps.txt
-----------------------
@echo off
set MVN_HOME=C:/Tools/apache-maven-3.6.3
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
set PATH=%MVN_HOME%/bin;%PATH%
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%~nH-SNAPSHOT -DgeneratePom=true -Dpackaging=jar -Dfile="%BUNDLES_HOME%/%%F/target/%%F-%%~nH-SNAPSHOT.jar"
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%H -DgeneratePom=true -Dpackaging=jar -Dfile="%ECLIPSE_HOME%/%%~nG.jar"
)
)
)
)
org.eclipse.ocl:org.eclipse.ocl
org.eclipse.ocl:org.eclipse.ocl.common
org.eclipse.ocl:org.eclipse.ocl.ecore
org.eclipse.ocl:org.eclipse.ocl.pivot
@echo off
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
break > deps-gen.txt
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%~nH-SNAPSHOT^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%H^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
)
)
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
:
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar \
-Dfile="$BUNDLES_HOME/$artifact/target/$artifact-$version.jar"
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar -Dfile="$file"
done
fi
done < deps.txt
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
: > deps-gen.txt
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
echo >> deps-gen.txt
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
done
fi
done < deps.txt
-----------------------
@echo off
set MVN_HOME=C:/Tools/apache-maven-3.6.3
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
set PATH=%MVN_HOME%/bin;%PATH%
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%~nH-SNAPSHOT -DgeneratePom=true -Dpackaging=jar -Dfile="%BUNDLES_HOME%/%%F/target/%%F-%%~nH-SNAPSHOT.jar"
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%H -DgeneratePom=true -Dpackaging=jar -Dfile="%ECLIPSE_HOME%/%%~nG.jar"
)
)
)
)
org.eclipse.ocl:org.eclipse.ocl
org.eclipse.ocl:org.eclipse.ocl.common
org.eclipse.ocl:org.eclipse.ocl.ecore
org.eclipse.ocl:org.eclipse.ocl.pivot
@echo off
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
break > deps-gen.txt
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%~nH-SNAPSHOT^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%H^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
)
)
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
:
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar \
-Dfile="$BUNDLES_HOME/$artifact/target/$artifact-$version.jar"
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar -Dfile="$file"
done
fi
done < deps.txt
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
: > deps-gen.txt
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
echo >> deps-gen.txt
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
done
fi
done < deps.txt
-----------------------
@echo off
set MVN_HOME=C:/Tools/apache-maven-3.6.3
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
set PATH=%MVN_HOME%/bin;%PATH%
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%~nH-SNAPSHOT -DgeneratePom=true -Dpackaging=jar -Dfile="%BUNDLES_HOME%/%%F/target/%%F-%%~nH-SNAPSHOT.jar"
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%H -DgeneratePom=true -Dpackaging=jar -Dfile="%ECLIPSE_HOME%/%%~nG.jar"
)
)
)
)
org.eclipse.ocl:org.eclipse.ocl
org.eclipse.ocl:org.eclipse.ocl.common
org.eclipse.ocl:org.eclipse.ocl.ecore
org.eclipse.ocl:org.eclipse.ocl.pivot
@echo off
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
break > deps-gen.txt
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%~nH-SNAPSHOT^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%H^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
)
)
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
:
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar \
-Dfile="$BUNDLES_HOME/$artifact/target/$artifact-$version.jar"
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar -Dfile="$file"
done
fi
done < deps.txt
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
: > deps-gen.txt
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
echo >> deps-gen.txt
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
done
fi
done < deps.txt
-----------------------
@echo off
set MVN_HOME=C:/Tools/apache-maven-3.6.3
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
set PATH=%MVN_HOME%/bin;%PATH%
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%~nH-SNAPSHOT -DgeneratePom=true -Dpackaging=jar -Dfile="%BUNDLES_HOME%/%%F/target/%%F-%%~nH-SNAPSHOT.jar"
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%H -DgeneratePom=true -Dpackaging=jar -Dfile="%ECLIPSE_HOME%/%%~nG.jar"
)
)
)
)
org.eclipse.ocl:org.eclipse.ocl
org.eclipse.ocl:org.eclipse.ocl.common
org.eclipse.ocl:org.eclipse.ocl.ecore
org.eclipse.ocl:org.eclipse.ocl.pivot
@echo off
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
break > deps-gen.txt
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%~nH-SNAPSHOT^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%H^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
)
)
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
:
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar \
-Dfile="$BUNDLES_HOME/$artifact/target/$artifact-$version.jar"
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar -Dfile="$file"
done
fi
done < deps.txt
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
: > deps-gen.txt
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
echo >> deps-gen.txt
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
done
fi
done < deps.txt
Karate - want to get url along with query params in a variable
Scenario: Sample File
* def ScenarioEngine = Java.type('com.intuit.karate.core.ScenarioEngine');
Given url 'https://reqres.in'
And path '/api/users'
And param page = 2
And param pages = 1
When method get
And print ScenarioEngine.get().getRequest().getUrl()
Python chess engine. Alphabeta function exceeding depth call error
import time
import chess
import chess.pgn
INF = 100000
MATE_SCORE = INF-100
MAX_DEPTH = 16
MAX_TIME_MS = 120000 # 120s or 2m
# Evaluating the board
pawntable = [
0, 0, 0, 0, 0, 0, 0, 0,
5, 10, 10, -20, -20, 10, 10, 5,
5, -5, -10, 0, 0, -10, -5, 5,
0, 0, 0, 20, 20, 0, 0, 0,
5, 5, 10, 25, 25, 10, 5, 5,
10, 10, 20, 30, 30, 20, 10, 10,
50, 50, 50, 50, 50, 50, 50, 50,
0, 0, 0, 0, 0, 0, 0, 0]
knightstable = [
-50, -40, -30, -30, -30, -30, -40, -50,
-40, -20, 0, 5, 5, 0, -20, -40,
-30, 5, 10, 15, 15, 10, 5, -30,
-30, 0, 15, 20, 20, 15, 0, -30,
-30, 5, 15, 20, 20, 15, 5, -30,
-30, 0, 10, 15, 15, 10, 0, -30,
-40, -20, 0, 0, 0, 0, -20, -40,
-50, -40, -30, -30, -30, -30, -40, -50]
bishopstable = [
-20, -10, -10, -10, -10, -10, -10, -20,
-10, 5, 0, 0, 0, 0, 5, -10,
-10, 10, 10, 10, 10, 10, 10, -10,
-10, 0, 10, 10, 10, 10, 0, -10,
-10, 5, 5, 10, 10, 5, 5, -10,
-10, 0, 5, 10, 10, 5, 0, -10,
-10, 0, 0, 0, 0, 0, 0, -10,
-20, -10, -10, -10, -10, -10, -10, -20]
rookstable = [
0, 0, 0, 5, 5, 0, 0, 0,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
5, 10, 10, 10, 10, 10, 10, 5,
0, 0, 0, 0, 0, 0, 0, 0]
queenstable = [
-20, -10, -10, -5, -5, -10, -10, -20,
-10, 0, 0, 0, 0, 0, 0, -10,
-10, 5, 5, 5, 5, 5, 0, -10,
0, 0, 5, 5, 5, 5, 0, -5,
-5, 0, 5, 5, 5, 5, 0, -5,
-10, 0, 5, 5, 5, 5, 0, -10,
-10, 0, 0, 0, 0, 0, 0, -10,
-20, -10, -10, -5, -5, -10, -10, -20]
kingstable = [
20, 30, 10, 0, 0, 10, 30, 20,
20, 20, 0, 0, 0, 0, 20, 20,
-10, -20, -20, -20, -20, -20, -20, -10,
-20, -30, -30, -40, -40, -30, -30, -20,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30]
def is_time_limit_reached():
global start_time
global timems
return 1000 * (time.perf_counter() - start_time) >= timems
def evaluate_board(board):
wp = len(board.pieces(chess.PAWN, chess.WHITE))
bp = len(board.pieces(chess.PAWN, chess.BLACK))
wn = len(board.pieces(chess.KNIGHT, chess.WHITE))
bn = len(board.pieces(chess.KNIGHT, chess.BLACK))
wb = len(board.pieces(chess.BISHOP, chess.WHITE))
bb = len(board.pieces(chess.BISHOP, chess.BLACK))
wr = len(board.pieces(chess.ROOK, chess.WHITE))
br = len(board.pieces(chess.ROOK, chess.BLACK))
wq = len(board.pieces(chess.QUEEN, chess.WHITE))
bq = len(board.pieces(chess.QUEEN, chess.BLACK))
material = 100 * (wp - bp) + 320 * (wn - bn) + 330 * (wb - bb) + 500 * (wr - br) + 900 * (wq - bq)
pawnsq = sum([pawntable[i] for i in board.pieces(chess.PAWN, chess.WHITE)])
pawnsq = pawnsq + sum([-pawntable[chess.square_mirror(i)]
for i in board.pieces(chess.PAWN, chess.BLACK)])
knightsq = sum([knightstable[i] for i in board.pieces(chess.KNIGHT, chess.WHITE)])
knightsq = knightsq + sum([-knightstable[chess.square_mirror(i)]
for i in board.pieces(chess.KNIGHT, chess.BLACK)])
bishopsq = sum([bishopstable[i] for i in board.pieces(chess.BISHOP, chess.WHITE)])
bishopsq = bishopsq + sum([-bishopstable[chess.square_mirror(i)]
for i in board.pieces(chess.BISHOP, chess.BLACK)])
rooksq = sum([rookstable[i] for i in board.pieces(chess.ROOK, chess.WHITE)])
rooksq = rooksq + sum([-rookstable[chess.square_mirror(i)]
for i in board.pieces(chess.ROOK, chess.BLACK)])
queensq = sum([queenstable[i] for i in board.pieces(chess.QUEEN, chess.WHITE)])
queensq = queensq + sum([-queenstable[chess.square_mirror(i)]
for i in board.pieces(chess.QUEEN, chess.BLACK)])
kingsq = sum([kingstable[i] for i in board.pieces(chess.KING, chess.WHITE)])
kingsq = kingsq + sum([-kingstable[chess.square_mirror(i)]
for i in board.pieces(chess.KING, chess.BLACK)])
eval = material + pawnsq + knightsq + bishopsq + rooksq + queensq + kingsq
if board.turn:
return eval
return -eval
def value_to_mate(value):
if (value < -MATE_SCORE):
return -(INF + value) // 2
elif (value > MATE_SCORE):
return (INF - value + 1) // 2
return 0
# Searching the best move using minimax and alphabeta algorithm with negamax implementation
def alphabeta(board, alpha, beta, depth):
global timems
global start_time
global ply
bestscore = -INF
if is_time_limit_reached():
return 0
if board.can_claim_draw() or board.is_insufficient_material():
return 0
incheck = board.is_check()
if incheck:
depth += 1
if (depth < 1):
return quiesce(board, alpha, beta)
legal = 0
for move in board.legal_moves:
board.push(move)
ply += 1
legal += 1
score = -alphabeta(board, -beta, -alpha, depth - 1)
board.pop()
ply -= 1
if (score >= beta):
return score
if (score > bestscore):
bestscore = score
if (score > alpha):
alpha = score
if legal == 0:
if incheck:
return -INF + ply
else:
return 0
return bestscore
def quiesce(board, alpha, beta):
if is_time_limit_reached():
return 0
if board.is_insufficient_material():
return 0
stand_pat = evaluate_board(board)
if (stand_pat >= beta):
return beta
if (alpha < stand_pat):
alpha = stand_pat
for move in board.legal_moves:
if board.is_capture(move):
board.push(move)
score = -quiesce(board, -beta, -alpha)
board.pop()
if (score >= beta):
return beta
if (score > alpha):
alpha = score
return alpha
def selectmove(board, depth):
global ply
bestMove = chess.Move.null()
bestValue = -INF
alpha = -INF
beta = INF
for move in board.legal_moves:
board.push(move)
ply += 1
boardValue = -alphabeta(board, -beta, -alpha, depth - 1)
if boardValue > bestValue:
bestValue = boardValue
bestMove = move
if (boardValue > alpha):
alpha = boardValue
board.pop()
ply -= 1
if is_time_limit_reached():
break
return bestMove, bestValue
if __name__ == '__main__':
global timems
global start_time
global ply
fen = chess.STARTING_FEN
# fen = "1k6/7Q/1K6/8/8/8/8/8 w - - 0 1" # mate in 1
# fen = "kbK5/pp6/1P6/8/8/8/8/R7 w - - 0 1" # mate in 2
# fen = "rnbqkb1r/1p2pppp/p2p1n2/8/3NP3/2N5/PPP2PPP/R1BQKB1R w KQkq - 0 6" # sicilian
depth = MAX_DEPTH
timems = MAX_TIME_MS
board = chess.Board(fen)
while True:
userinput = input('> ')
line = userinput.rstrip()
if line == 'go':
bestmove, bestscore = None, None
start_time = time.perf_counter()
ply = 0
if not board.is_game_over():
for d in range(1, depth+1):
move, score = selectmove(board, d)
elapse = 1000 * (time.perf_counter() - start_time)
if elapse >= timems:
break # Don't overwrite our bestmove from the time-interrupted search.
bestmove = move
bestscore = score
if abs(bestscore) > MATE_SCORE:
mate = value_to_mate(bestscore)
print(f'info depth {d} score mate {mate} time {int(elapse)} pv {bestmove}') # time is in millisec
else:
print(f'info depth {d} score {bestscore} time {int(elapse)} pv {bestmove}') # time is in millisec
board.push(bestmove) # update board with the bestmove
print(f'info time {int(1000*(time.perf_counter() - start_time))}')
print(f'bestmove {bestmove}')
else:
print('Game is over!')
elif line == 'new':
board = chess.Board()
depth = MAX_DEPTH
timems = MAX_TIME_MS
print(board)
print(f'max depth: {depth}, max time ms: {timems}')
elif 'position fen ' in line:
fen = ' '.join(line.split()[2:7])
board = chess.Board(fen)
elif line == 'board':
print(board)
elif line == 'fen':
print(board.fen())
elif line == 'epd':
print(board.epd())
elif 'time' in line:
timems = int(line.split()[1])
elif 'depth' in line:
depth = int(line.split()[1])
elif line == 'game':
game = chess.pgn.Game()
print(game.from_board(board))
elif line == 'quit':
break
else:
# assume user has entered a move
try:
board.push(chess.Move.from_uci(line))
except ValueError:
print(f'illegal move {line}')
> new
r n b q k b n r
p p p p p p p p
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
P P P P P P P P
R N B Q K B N R
max depth: 16, max time ms: 120000
> time 5000
> e2e4
> go
info depth 1 score 10 time 18 pv g8f6
info depth 2 score -40 time 140 pv g8f6
info depth 3 score 10 time 973 pv g8f6
info time 5001
bestmove g8f6
> board
r n b q k b . r
p p p p p p p p
. . . . . n . .
. . . . . . . .
. . . . P . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R
> b1c3
> go
info depth 1 score 10 time 19 pv b8c6
info depth 2 score -20 time 421 pv d7d5
info depth 3 score 10 time 2865 pv d7d5
info time 5000
bestmove d7d5
> board
r n b q k b . r
p p p . p p p p
. . . . . n . .
. . . p . . . .
. . . . P . . .
. . N . . . . .
P P P P . P P P
R . B Q K B N R
> game
[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]
1. e4 Nf6 2. Nc3 d5 *
> quit
> position fen kbK5/pp6/1P6/8/8/8/8/R7 w - - 0 1
> board
k b K . . . . .
p p . . . . . .
. P . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
R . . . . . . .
> time 5000
> go
info depth 1 score 10 time 10 pv a1a5
info depth 2 score 10 time 92 pv a1a5
info depth 3 score mate 2 time 362 pv a1a6
info depth 4 score mate 2 time 2151 pv a1a6
info time 5001
bestmove a1a6
> board
k b K . . . . .
p p . . . . . .
R P . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
> go
info depth 1 score 480 time 5 pv b7a6
info depth 2 score mate -1 time 32 pv b8c7
info depth 3 score mate -1 time 184 pv b8c7
info depth 4 score mate -1 time 1314 pv b8c7
info time 5000
bestmove b8c7
> go
info depth 1 score mate 1 time 4 pv a6a7
info depth 2 score mate 1 time 37 pv a6a7
info depth 3 score mate 1 time 143 pv a6a7
info depth 4 score mate 1 time 878 pv a6a7
info depth 5 score mate 1 time 4305 pv a6a7
info time 5001
bestmove a6a7
> go
Game is over!
>
-----------------------
import time
import chess
import chess.pgn
INF = 100000
MATE_SCORE = INF-100
MAX_DEPTH = 16
MAX_TIME_MS = 120000 # 120s or 2m
# Evaluating the board
pawntable = [
0, 0, 0, 0, 0, 0, 0, 0,
5, 10, 10, -20, -20, 10, 10, 5,
5, -5, -10, 0, 0, -10, -5, 5,
0, 0, 0, 20, 20, 0, 0, 0,
5, 5, 10, 25, 25, 10, 5, 5,
10, 10, 20, 30, 30, 20, 10, 10,
50, 50, 50, 50, 50, 50, 50, 50,
0, 0, 0, 0, 0, 0, 0, 0]
knightstable = [
-50, -40, -30, -30, -30, -30, -40, -50,
-40, -20, 0, 5, 5, 0, -20, -40,
-30, 5, 10, 15, 15, 10, 5, -30,
-30, 0, 15, 20, 20, 15, 0, -30,
-30, 5, 15, 20, 20, 15, 5, -30,
-30, 0, 10, 15, 15, 10, 0, -30,
-40, -20, 0, 0, 0, 0, -20, -40,
-50, -40, -30, -30, -30, -30, -40, -50]
bishopstable = [
-20, -10, -10, -10, -10, -10, -10, -20,
-10, 5, 0, 0, 0, 0, 5, -10,
-10, 10, 10, 10, 10, 10, 10, -10,
-10, 0, 10, 10, 10, 10, 0, -10,
-10, 5, 5, 10, 10, 5, 5, -10,
-10, 0, 5, 10, 10, 5, 0, -10,
-10, 0, 0, 0, 0, 0, 0, -10,
-20, -10, -10, -10, -10, -10, -10, -20]
rookstable = [
0, 0, 0, 5, 5, 0, 0, 0,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
5, 10, 10, 10, 10, 10, 10, 5,
0, 0, 0, 0, 0, 0, 0, 0]
queenstable = [
-20, -10, -10, -5, -5, -10, -10, -20,
-10, 0, 0, 0, 0, 0, 0, -10,
-10, 5, 5, 5, 5, 5, 0, -10,
0, 0, 5, 5, 5, 5, 0, -5,
-5, 0, 5, 5, 5, 5, 0, -5,
-10, 0, 5, 5, 5, 5, 0, -10,
-10, 0, 0, 0, 0, 0, 0, -10,
-20, -10, -10, -5, -5, -10, -10, -20]
kingstable = [
20, 30, 10, 0, 0, 10, 30, 20,
20, 20, 0, 0, 0, 0, 20, 20,
-10, -20, -20, -20, -20, -20, -20, -10,
-20, -30, -30, -40, -40, -30, -30, -20,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30]
def is_time_limit_reached():
global start_time
global timems
return 1000 * (time.perf_counter() - start_time) >= timems
def evaluate_board(board):
wp = len(board.pieces(chess.PAWN, chess.WHITE))
bp = len(board.pieces(chess.PAWN, chess.BLACK))
wn = len(board.pieces(chess.KNIGHT, chess.WHITE))
bn = len(board.pieces(chess.KNIGHT, chess.BLACK))
wb = len(board.pieces(chess.BISHOP, chess.WHITE))
bb = len(board.pieces(chess.BISHOP, chess.BLACK))
wr = len(board.pieces(chess.ROOK, chess.WHITE))
br = len(board.pieces(chess.ROOK, chess.BLACK))
wq = len(board.pieces(chess.QUEEN, chess.WHITE))
bq = len(board.pieces(chess.QUEEN, chess.BLACK))
material = 100 * (wp - bp) + 320 * (wn - bn) + 330 * (wb - bb) + 500 * (wr - br) + 900 * (wq - bq)
pawnsq = sum([pawntable[i] for i in board.pieces(chess.PAWN, chess.WHITE)])
pawnsq = pawnsq + sum([-pawntable[chess.square_mirror(i)]
for i in board.pieces(chess.PAWN, chess.BLACK)])
knightsq = sum([knightstable[i] for i in board.pieces(chess.KNIGHT, chess.WHITE)])
knightsq = knightsq + sum([-knightstable[chess.square_mirror(i)]
for i in board.pieces(chess.KNIGHT, chess.BLACK)])
bishopsq = sum([bishopstable[i] for i in board.pieces(chess.BISHOP, chess.WHITE)])
bishopsq = bishopsq + sum([-bishopstable[chess.square_mirror(i)]
for i in board.pieces(chess.BISHOP, chess.BLACK)])
rooksq = sum([rookstable[i] for i in board.pieces(chess.ROOK, chess.WHITE)])
rooksq = rooksq + sum([-rookstable[chess.square_mirror(i)]
for i in board.pieces(chess.ROOK, chess.BLACK)])
queensq = sum([queenstable[i] for i in board.pieces(chess.QUEEN, chess.WHITE)])
queensq = queensq + sum([-queenstable[chess.square_mirror(i)]
for i in board.pieces(chess.QUEEN, chess.BLACK)])
kingsq = sum([kingstable[i] for i in board.pieces(chess.KING, chess.WHITE)])
kingsq = kingsq + sum([-kingstable[chess.square_mirror(i)]
for i in board.pieces(chess.KING, chess.BLACK)])
eval = material + pawnsq + knightsq + bishopsq + rooksq + queensq + kingsq
if board.turn:
return eval
return -eval
def value_to_mate(value):
if (value < -MATE_SCORE):
return -(INF + value) // 2
elif (value > MATE_SCORE):
return (INF - value + 1) // 2
return 0
# Searching the best move using minimax and alphabeta algorithm with negamax implementation
def alphabeta(board, alpha, beta, depth):
global timems
global start_time
global ply
bestscore = -INF
if is_time_limit_reached():
return 0
if board.can_claim_draw() or board.is_insufficient_material():
return 0
incheck = board.is_check()
if incheck:
depth += 1
if (depth < 1):
return quiesce(board, alpha, beta)
legal = 0
for move in board.legal_moves:
board.push(move)
ply += 1
legal += 1
score = -alphabeta(board, -beta, -alpha, depth - 1)
board.pop()
ply -= 1
if (score >= beta):
return score
if (score > bestscore):
bestscore = score
if (score > alpha):
alpha = score
if legal == 0:
if incheck:
return -INF + ply
else:
return 0
return bestscore
def quiesce(board, alpha, beta):
if is_time_limit_reached():
return 0
if board.is_insufficient_material():
return 0
stand_pat = evaluate_board(board)
if (stand_pat >= beta):
return beta
if (alpha < stand_pat):
alpha = stand_pat
for move in board.legal_moves:
if board.is_capture(move):
board.push(move)
score = -quiesce(board, -beta, -alpha)
board.pop()
if (score >= beta):
return beta
if (score > alpha):
alpha = score
return alpha
def selectmove(board, depth):
global ply
bestMove = chess.Move.null()
bestValue = -INF
alpha = -INF
beta = INF
for move in board.legal_moves:
board.push(move)
ply += 1
boardValue = -alphabeta(board, -beta, -alpha, depth - 1)
if boardValue > bestValue:
bestValue = boardValue
bestMove = move
if (boardValue > alpha):
alpha = boardValue
board.pop()
ply -= 1
if is_time_limit_reached():
break
return bestMove, bestValue
if __name__ == '__main__':
global timems
global start_time
global ply
fen = chess.STARTING_FEN
# fen = "1k6/7Q/1K6/8/8/8/8/8 w - - 0 1" # mate in 1
# fen = "kbK5/pp6/1P6/8/8/8/8/R7 w - - 0 1" # mate in 2
# fen = "rnbqkb1r/1p2pppp/p2p1n2/8/3NP3/2N5/PPP2PPP/R1BQKB1R w KQkq - 0 6" # sicilian
depth = MAX_DEPTH
timems = MAX_TIME_MS
board = chess.Board(fen)
while True:
userinput = input('> ')
line = userinput.rstrip()
if line == 'go':
bestmove, bestscore = None, None
start_time = time.perf_counter()
ply = 0
if not board.is_game_over():
for d in range(1, depth+1):
move, score = selectmove(board, d)
elapse = 1000 * (time.perf_counter() - start_time)
if elapse >= timems:
break # Don't overwrite our bestmove from the time-interrupted search.
bestmove = move
bestscore = score
if abs(bestscore) > MATE_SCORE:
mate = value_to_mate(bestscore)
print(f'info depth {d} score mate {mate} time {int(elapse)} pv {bestmove}') # time is in millisec
else:
print(f'info depth {d} score {bestscore} time {int(elapse)} pv {bestmove}') # time is in millisec
board.push(bestmove) # update board with the bestmove
print(f'info time {int(1000*(time.perf_counter() - start_time))}')
print(f'bestmove {bestmove}')
else:
print('Game is over!')
elif line == 'new':
board = chess.Board()
depth = MAX_DEPTH
timems = MAX_TIME_MS
print(board)
print(f'max depth: {depth}, max time ms: {timems}')
elif 'position fen ' in line:
fen = ' '.join(line.split()[2:7])
board = chess.Board(fen)
elif line == 'board':
print(board)
elif line == 'fen':
print(board.fen())
elif line == 'epd':
print(board.epd())
elif 'time' in line:
timems = int(line.split()[1])
elif 'depth' in line:
depth = int(line.split()[1])
elif line == 'game':
game = chess.pgn.Game()
print(game.from_board(board))
elif line == 'quit':
break
else:
# assume user has entered a move
try:
board.push(chess.Move.from_uci(line))
except ValueError:
print(f'illegal move {line}')
> new
r n b q k b n r
p p p p p p p p
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
P P P P P P P P
R N B Q K B N R
max depth: 16, max time ms: 120000
> time 5000
> e2e4
> go
info depth 1 score 10 time 18 pv g8f6
info depth 2 score -40 time 140 pv g8f6
info depth 3 score 10 time 973 pv g8f6
info time 5001
bestmove g8f6
> board
r n b q k b . r
p p p p p p p p
. . . . . n . .
. . . . . . . .
. . . . P . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R
> b1c3
> go
info depth 1 score 10 time 19 pv b8c6
info depth 2 score -20 time 421 pv d7d5
info depth 3 score 10 time 2865 pv d7d5
info time 5000
bestmove d7d5
> board
r n b q k b . r
p p p . p p p p
. . . . . n . .
. . . p . . . .
. . . . P . . .
. . N . . . . .
P P P P . P P P
R . B Q K B N R
> game
[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]
1. e4 Nf6 2. Nc3 d5 *
> quit
> position fen kbK5/pp6/1P6/8/8/8/8/R7 w - - 0 1
> board
k b K . . . . .
p p . . . . . .
. P . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
R . . . . . . .
> time 5000
> go
info depth 1 score 10 time 10 pv a1a5
info depth 2 score 10 time 92 pv a1a5
info depth 3 score mate 2 time 362 pv a1a6
info depth 4 score mate 2 time 2151 pv a1a6
info time 5001
bestmove a1a6
> board
k b K . . . . .
p p . . . . . .
R P . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
> go
info depth 1 score 480 time 5 pv b7a6
info depth 2 score mate -1 time 32 pv b8c7
info depth 3 score mate -1 time 184 pv b8c7
info depth 4 score mate -1 time 1314 pv b8c7
info time 5000
bestmove b8c7
> go
info depth 1 score mate 1 time 4 pv a6a7
info depth 2 score mate 1 time 37 pv a6a7
info depth 3 score mate 1 time 143 pv a6a7
info depth 4 score mate 1 time 878 pv a6a7
info depth 5 score mate 1 time 4305 pv a6a7
info time 5001
bestmove a6a7
> go
Game is over!
>
-----------------------
import time
import chess
import chess.pgn
INF = 100000
MATE_SCORE = INF-100
MAX_DEPTH = 16
MAX_TIME_MS = 120000 # 120s or 2m
# Evaluating the board
pawntable = [
0, 0, 0, 0, 0, 0, 0, 0,
5, 10, 10, -20, -20, 10, 10, 5,
5, -5, -10, 0, 0, -10, -5, 5,
0, 0, 0, 20, 20, 0, 0, 0,
5, 5, 10, 25, 25, 10, 5, 5,
10, 10, 20, 30, 30, 20, 10, 10,
50, 50, 50, 50, 50, 50, 50, 50,
0, 0, 0, 0, 0, 0, 0, 0]
knightstable = [
-50, -40, -30, -30, -30, -30, -40, -50,
-40, -20, 0, 5, 5, 0, -20, -40,
-30, 5, 10, 15, 15, 10, 5, -30,
-30, 0, 15, 20, 20, 15, 0, -30,
-30, 5, 15, 20, 20, 15, 5, -30,
-30, 0, 10, 15, 15, 10, 0, -30,
-40, -20, 0, 0, 0, 0, -20, -40,
-50, -40, -30, -30, -30, -30, -40, -50]
bishopstable = [
-20, -10, -10, -10, -10, -10, -10, -20,
-10, 5, 0, 0, 0, 0, 5, -10,
-10, 10, 10, 10, 10, 10, 10, -10,
-10, 0, 10, 10, 10, 10, 0, -10,
-10, 5, 5, 10, 10, 5, 5, -10,
-10, 0, 5, 10, 10, 5, 0, -10,
-10, 0, 0, 0, 0, 0, 0, -10,
-20, -10, -10, -10, -10, -10, -10, -20]
rookstable = [
0, 0, 0, 5, 5, 0, 0, 0,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
5, 10, 10, 10, 10, 10, 10, 5,
0, 0, 0, 0, 0, 0, 0, 0]
queenstable = [
-20, -10, -10, -5, -5, -10, -10, -20,
-10, 0, 0, 0, 0, 0, 0, -10,
-10, 5, 5, 5, 5, 5, 0, -10,
0, 0, 5, 5, 5, 5, 0, -5,
-5, 0, 5, 5, 5, 5, 0, -5,
-10, 0, 5, 5, 5, 5, 0, -10,
-10, 0, 0, 0, 0, 0, 0, -10,
-20, -10, -10, -5, -5, -10, -10, -20]
kingstable = [
20, 30, 10, 0, 0, 10, 30, 20,
20, 20, 0, 0, 0, 0, 20, 20,
-10, -20, -20, -20, -20, -20, -20, -10,
-20, -30, -30, -40, -40, -30, -30, -20,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30]
def is_time_limit_reached():
global start_time
global timems
return 1000 * (time.perf_counter() - start_time) >= timems
def evaluate_board(board):
wp = len(board.pieces(chess.PAWN, chess.WHITE))
bp = len(board.pieces(chess.PAWN, chess.BLACK))
wn = len(board.pieces(chess.KNIGHT, chess.WHITE))
bn = len(board.pieces(chess.KNIGHT, chess.BLACK))
wb = len(board.pieces(chess.BISHOP, chess.WHITE))
bb = len(board.pieces(chess.BISHOP, chess.BLACK))
wr = len(board.pieces(chess.ROOK, chess.WHITE))
br = len(board.pieces(chess.ROOK, chess.BLACK))
wq = len(board.pieces(chess.QUEEN, chess.WHITE))
bq = len(board.pieces(chess.QUEEN, chess.BLACK))
material = 100 * (wp - bp) + 320 * (wn - bn) + 330 * (wb - bb) + 500 * (wr - br) + 900 * (wq - bq)
pawnsq = sum([pawntable[i] for i in board.pieces(chess.PAWN, chess.WHITE)])
pawnsq = pawnsq + sum([-pawntable[chess.square_mirror(i)]
for i in board.pieces(chess.PAWN, chess.BLACK)])
knightsq = sum([knightstable[i] for i in board.pieces(chess.KNIGHT, chess.WHITE)])
knightsq = knightsq + sum([-knightstable[chess.square_mirror(i)]
for i in board.pieces(chess.KNIGHT, chess.BLACK)])
bishopsq = sum([bishopstable[i] for i in board.pieces(chess.BISHOP, chess.WHITE)])
bishopsq = bishopsq + sum([-bishopstable[chess.square_mirror(i)]
for i in board.pieces(chess.BISHOP, chess.BLACK)])
rooksq = sum([rookstable[i] for i in board.pieces(chess.ROOK, chess.WHITE)])
rooksq = rooksq + sum([-rookstable[chess.square_mirror(i)]
for i in board.pieces(chess.ROOK, chess.BLACK)])
queensq = sum([queenstable[i] for i in board.pieces(chess.QUEEN, chess.WHITE)])
queensq = queensq + sum([-queenstable[chess.square_mirror(i)]
for i in board.pieces(chess.QUEEN, chess.BLACK)])
kingsq = sum([kingstable[i] for i in board.pieces(chess.KING, chess.WHITE)])
kingsq = kingsq + sum([-kingstable[chess.square_mirror(i)]
for i in board.pieces(chess.KING, chess.BLACK)])
eval = material + pawnsq + knightsq + bishopsq + rooksq + queensq + kingsq
if board.turn:
return eval
return -eval
def value_to_mate(value):
if (value < -MATE_SCORE):
return -(INF + value) // 2
elif (value > MATE_SCORE):
return (INF - value + 1) // 2
return 0
# Searching the best move using minimax and alphabeta algorithm with negamax implementation
def alphabeta(board, alpha, beta, depth):
global timems
global start_time
global ply
bestscore = -INF
if is_time_limit_reached():
return 0
if board.can_claim_draw() or board.is_insufficient_material():
return 0
incheck = board.is_check()
if incheck:
depth += 1
if (depth < 1):
return quiesce(board, alpha, beta)
legal = 0
for move in board.legal_moves:
board.push(move)
ply += 1
legal += 1
score = -alphabeta(board, -beta, -alpha, depth - 1)
board.pop()
ply -= 1
if (score >= beta):
return score
if (score > bestscore):
bestscore = score
if (score > alpha):
alpha = score
if legal == 0:
if incheck:
return -INF + ply
else:
return 0
return bestscore
def quiesce(board, alpha, beta):
if is_time_limit_reached():
return 0
if board.is_insufficient_material():
return 0
stand_pat = evaluate_board(board)
if (stand_pat >= beta):
return beta
if (alpha < stand_pat):
alpha = stand_pat
for move in board.legal_moves:
if board.is_capture(move):
board.push(move)
score = -quiesce(board, -beta, -alpha)
board.pop()
if (score >= beta):
return beta
if (score > alpha):
alpha = score
return alpha
def selectmove(board, depth):
global ply
bestMove = chess.Move.null()
bestValue = -INF
alpha = -INF
beta = INF
for move in board.legal_moves:
board.push(move)
ply += 1
boardValue = -alphabeta(board, -beta, -alpha, depth - 1)
if boardValue > bestValue:
bestValue = boardValue
bestMove = move
if (boardValue > alpha):
alpha = boardValue
board.pop()
ply -= 1
if is_time_limit_reached():
break
return bestMove, bestValue
if __name__ == '__main__':
global timems
global start_time
global ply
fen = chess.STARTING_FEN
# fen = "1k6/7Q/1K6/8/8/8/8/8 w - - 0 1" # mate in 1
# fen = "kbK5/pp6/1P6/8/8/8/8/R7 w - - 0 1" # mate in 2
# fen = "rnbqkb1r/1p2pppp/p2p1n2/8/3NP3/2N5/PPP2PPP/R1BQKB1R w KQkq - 0 6" # sicilian
depth = MAX_DEPTH
timems = MAX_TIME_MS
board = chess.Board(fen)
while True:
userinput = input('> ')
line = userinput.rstrip()
if line == 'go':
bestmove, bestscore = None, None
start_time = time.perf_counter()
ply = 0
if not board.is_game_over():
for d in range(1, depth+1):
move, score = selectmove(board, d)
elapse = 1000 * (time.perf_counter() - start_time)
if elapse >= timems:
break # Don't overwrite our bestmove from the time-interrupted search.
bestmove = move
bestscore = score
if abs(bestscore) > MATE_SCORE:
mate = value_to_mate(bestscore)
print(f'info depth {d} score mate {mate} time {int(elapse)} pv {bestmove}') # time is in millisec
else:
print(f'info depth {d} score {bestscore} time {int(elapse)} pv {bestmove}') # time is in millisec
board.push(bestmove) # update board with the bestmove
print(f'info time {int(1000*(time.perf_counter() - start_time))}')
print(f'bestmove {bestmove}')
else:
print('Game is over!')
elif line == 'new':
board = chess.Board()
depth = MAX_DEPTH
timems = MAX_TIME_MS
print(board)
print(f'max depth: {depth}, max time ms: {timems}')
elif 'position fen ' in line:
fen = ' '.join(line.split()[2:7])
board = chess.Board(fen)
elif line == 'board':
print(board)
elif line == 'fen':
print(board.fen())
elif line == 'epd':
print(board.epd())
elif 'time' in line:
timems = int(line.split()[1])
elif 'depth' in line:
depth = int(line.split()[1])
elif line == 'game':
game = chess.pgn.Game()
print(game.from_board(board))
elif line == 'quit':
break
else:
# assume user has entered a move
try:
board.push(chess.Move.from_uci(line))
except ValueError:
print(f'illegal move {line}')
> new
r n b q k b n r
p p p p p p p p
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
P P P P P P P P
R N B Q K B N R
max depth: 16, max time ms: 120000
> time 5000
> e2e4
> go
info depth 1 score 10 time 18 pv g8f6
info depth 2 score -40 time 140 pv g8f6
info depth 3 score 10 time 973 pv g8f6
info time 5001
bestmove g8f6
> board
r n b q k b . r
p p p p p p p p
. . . . . n . .
. . . . . . . .
. . . . P . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R
> b1c3
> go
info depth 1 score 10 time 19 pv b8c6
info depth 2 score -20 time 421 pv d7d5
info depth 3 score 10 time 2865 pv d7d5
info time 5000
bestmove d7d5
> board
r n b q k b . r
p p p . p p p p
. . . . . n . .
. . . p . . . .
. . . . P . . .
. . N . . . . .
P P P P . P P P
R . B Q K B N R
> game
[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]
1. e4 Nf6 2. Nc3 d5 *
> quit
> position fen kbK5/pp6/1P6/8/8/8/8/R7 w - - 0 1
> board
k b K . . . . .
p p . . . . . .
. P . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
R . . . . . . .
> time 5000
> go
info depth 1 score 10 time 10 pv a1a5
info depth 2 score 10 time 92 pv a1a5
info depth 3 score mate 2 time 362 pv a1a6
info depth 4 score mate 2 time 2151 pv a1a6
info time 5001
bestmove a1a6
> board
k b K . . . . .
p p . . . . . .
R P . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
> go
info depth 1 score 480 time 5 pv b7a6
info depth 2 score mate -1 time 32 pv b8c7
info depth 3 score mate -1 time 184 pv b8c7
info depth 4 score mate -1 time 1314 pv b8c7
info time 5000
bestmove b8c7
> go
info depth 1 score mate 1 time 4 pv a6a7
info depth 2 score mate 1 time 37 pv a6a7
info depth 3 score mate 1 time 143 pv a6a7
info depth 4 score mate 1 time 878 pv a6a7
info depth 5 score mate 1 time 4305 pv a6a7
info time 5001
bestmove a6a7
> go
Game is over!
>
I have to store a particular value in response of one API into two arrays in karate where array length can be even or odd number
* def list = [1, 2, 3, 4]
* def odd1 = list.filter(x => x % 2)
* match odd1 == [1, 3]
* def odd2 = karate.filter(list, function(x){ return x % 2 != 0 })
* match odd2 == [1, 3]
* def even = list.filter((x, i) => i % 2)
* match even == [2, 4]
* def odd = []
* def list = [1, 2, 3, 4]
* list.forEach(x => {if (x % 2) odd.push(x)})
* match odd == [1, 3]
-----------------------
* def list = [1, 2, 3, 4]
* def odd1 = list.filter(x => x % 2)
* match odd1 == [1, 3]
* def odd2 = karate.filter(list, function(x){ return x % 2 != 0 })
* match odd2 == [1, 3]
* def even = list.filter((x, i) => i % 2)
* match even == [2, 4]
* def odd = []
* def list = [1, 2, 3, 4]
* list.forEach(x => {if (x % 2) odd.push(x)})
* match odd == [1, 3]
How to apply if condition on the basis of response header in karate
* if (karate.get("responseHeaders['APP-ID'][0]")) karate.call('called.feature', { id: 'foo' })
QUESTION
Karate - Get CSV column value having space
Asked 2022-Mar-25 at 12:52I want to get the 'Instrument ID' column value of the below CSV data where the CSV column header having spaces
Instrument ID, Instrument Name
SS-01,TestData
This is my code
* json csvContents = read('instument-info.csv')
* print csvContents
* print csvContents[0]
* print csvContents[0].Instrument ID
But its throws the below error
01: karate.log('[print]',csvContents[0].Instrument ID)
<<<<
org.graalvm.polyglot.PolyglotException: SyntaxError: Unnamed:1:43 Expected , but found ID
karate.log('[print]',csvContents[0].Instrument ID)
ANSWER
Answered 2022-Mar-25 at 12:52Use the JS "bracket" notation. For example, try this:
* csv data =
"""
Instrument ID, Instrument Name
SS-01,TestData
"""
* match data[0]['Instrument ID'] == 'SS-01'
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit